xT30x

Untitled

Feb 19th, 2023
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 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.         ll nos = 0;
  18.         string s;
  19.         cin.ignore();
  20.         getline(cin, s);
  21.         vector<list<char>> v{{}, {}};
  22.         ll pos = 1;
  23.         ll le = 0;
  24.         ll ls = 0;
  25.         char ads = ']';
  26.         for (auto cl : s)
  27.         {
  28.             if (cl == ']' || cl == '[')
  29.             {
  30.                 if (ads == ']')
  31.                 {
  32.                     v.at(le).splice(v.at(le).end(), v.at(pos));
  33.                     v.push_back({});
  34.                     le = pos;
  35.                     pos += 1;
  36.                 }
  37.                 else
  38.                 {
  39.                     v.at(pos).splice(v.at(pos).end(), v.at(ls));
  40.                     v.push_back({});
  41.                     ls = pos;
  42.                     pos += 1;
  43.                 }
  44.             }
  45.             else if (cl == '<')
  46.             {
  47.                 if (!v.at(pos).empty())
  48.                 {
  49.                     v.at(pos).pop_back();
  50.                 }
  51.             }
  52.             else
  53.             {
  54.                 nos++;
  55.                 v.at(pos).push_back(cl);
  56.             }
  57.         }
  58.         v.at(le).splice(v.at(le).end(), v.at(pos));
  59.         auto it = v.at(ls).begin();
  60.  
  61.         for (int i = 0; i < nos; i++)
  62.         {
  63.             cout << *it;
  64.             it++;
  65.         }
  66.         cout << endl;
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment