xT30x

Untitled

Feb 18th, 2023
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define prm(x) x.begin(), x.end()
  4. #define srt(x) sort(prm(x))
  5. #define rvs(x) reverse(prm(x))
  6.  
  7. using namespace std;
  8. using ll = long long;
  9. using ld = long double;
  10.  
  11. int main()
  12. {
  13.     ll tc;
  14.     cin >> tc;
  15.     while (tc-- > 0)
  16.     {
  17.         string s;
  18.         cin.ignore();
  19.         getline(cin, s);
  20.         vector<list<char>> v{{}, {}};
  21.         ll pos = 1;
  22.         ll le = 0;
  23.         ll ls = 0;
  24.         char ads = ']';
  25.         for (auto cl : s)
  26.         {
  27.             if (cl == ']' || cl == '[')
  28.             {
  29.                 if (ads == ']')
  30.                 {
  31.                     v.at(le).splice(v.at(le).end(), v.at(pos));
  32.                     v.push_back({});
  33.                     le = pos;
  34.                     pos += 1;
  35.                 }
  36.                 else
  37.                 {
  38.                     v.at(pos).splice(v.at(pos).end(), v.at(ls));
  39.                     v.push_back({});
  40.                     ls = pos;
  41.                     pos += 1;
  42.                 }
  43.             }
  44.             else if (cl == '<')
  45.             {
  46.                 v.at(pos).pop_back();
  47.             }
  48.             else
  49.             {
  50.                 v.at(pos).push_back(cl);
  51.             }
  52.         }
  53.         auto it = v.at(ls).begin();
  54.         for (int i = 0; i < v.size(); i++)
  55.         {
  56.             for (auto cl : v.at(*it))
  57.             {
  58.                 cout << cl;
  59.             }
  60.             it++;
  61.         }
  62.     }
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment