Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #include<bits/stdc++.h>
- using namespace std;
- int main() {
- //freopen("in.txt", "r", stdin);
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- int idx = 1;
- deque<int> a;
- deque<int> b;
- for (int i = 0; i < n; ++i) {
- char ch;
- cin >> ch;
- if (ch == 'a') {
- a.push_back((idx++) % 10);
- }
- if (ch == 'b') {
- b.push_back((idx++)% 10);
- }
- if (ch == 'A') {
- cout << a.front();
- a.pop_front();
- }
- if (ch == 'B') {
- cout << b.front();
- b.pop_front();
- }
- if (ch == '>') {
- while (a.size() > 0) {
- b.push_back(a.back());
- a.pop_back();
- }
- }
- if (ch == '<') {
- while ((int)b.size() - 1 >= (int)a.size() + 1) {
- a.push_back(b.back());
- b.pop_back();
- }
- }
- if (ch == ']') {
- while (!b.empty()) {
- a.push_back(b.back());
- b.pop_back();
- }
- }
- if (ch == '[') {
- while ((int)a.size() - 1 >= (int)b.size() + 1) {
- b.push_back(a.back());
- a.pop_back();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement