xT30x

Untitled

Feb 19th, 2023
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 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.                 if (!v.at(pos).empty())
  47.                 {
  48.                     v.at(pos).pop_back();
  49.                 }
  50.             }
  51.             else
  52.             {
  53.                 v.at(pos).push_back(cl);
  54.             }
  55.         }
  56.         cout << 1 << endl;
  57.         for (auto it = v.at(ls).begin(); it != v.at(ls).end(); it++)
  58.         {
  59.             cout << *it;
  60.         }
  61.         cout << endl;
  62.     }
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment