Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define prm(x) x.begin(), x.end()
- #define srt(x) sort(prm(x))
- #define rvs(x) reverse(prm(x))
- using namespace std;
- using ll = long long;
- using ld = long double;
- int main()
- {
- ll tc;
- cin >> tc;
- while (tc-- > 0)
- {
- string s;
- cin.ignore();
- getline(cin, s);
- vector<list<char>> v{{}, {}};
- ll pos = 1;
- ll le = 0;
- ll ls = 0;
- char ads = ']';
- for (auto cl : s)
- {
- if (cl == ']' || cl == '[')
- {
- if (ads == ']')
- {
- v.at(le).splice(v.at(le).end(), v.at(pos));
- v.push_back({});
- le = pos;
- pos += 1;
- }
- else
- {
- v.at(pos).splice(v.at(pos).end(), v.at(ls));
- v.push_back({});
- ls = pos;
- pos += 1;
- }
- }
- else if (cl == '<')
- {
- v.at(pos).pop_back();
- }
- else
- {
- v.at(pos).push_back(cl);
- }
- }
- auto it = v.at(ls).begin();
- for (int i = 0; i < v.size(); i++)
- {
- for (auto cl : v.at(*it))
- {
- cout << cl;
- }
- it++;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment