fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
  4. #define ll long long
  5. #define endl '\n'
  6.  
  7. void fileIO() {
  8. #ifndef ONLINE_JUDGE
  9. freopen("input.txt", "r", stdin);
  10. freopen("output.txt", "w", stdout);
  11. #endif
  12. }
  13.  
  14. void solve() {
  15. string s;
  16.  
  17. while (cin >> s) {
  18. queue<char> a;
  19. queue<char> b;
  20.  
  21. int flag = 0;
  22.  
  23. for (int i = 0; i < s.size(); i++) {
  24. char c = s[i];
  25. if (c == '[') {
  26. flag++;
  27. }
  28. else if (c == ']') {
  29. flag--;
  30. }
  31. else {
  32. if (flag > 0) b.push(c);
  33. else a.push(c);
  34. }
  35. }
  36.  
  37. while (!b.empty()) {
  38. cout << b.front();
  39. b.pop();
  40. }
  41.  
  42. while (!a.empty()) {
  43. cout << a.front();
  44. a.pop();
  45. }
  46.  
  47. cout << endl;
  48. }
  49. }
  50.  
  51. int main() {
  52. IOS;
  53. fileIO();
  54.  
  55. int testCases = 1;
  56. // cin >> testCases;
  57. while (testCases--) {
  58. solve();
  59. }
  60. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty