Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define mp make_pair
- #define x first
- #define y second
- #define pb push_back
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- deque<int> a[2];
- bool use[2];
- void add(int t, int x) {
- if (use[t]) {
- a[1 - t].push_front(x);
- } else {
- a[t].push_back(x);
- }
- }
- int get(int t) {
- int ans;
- if (a[t].empty()) {
- ans = a[1 - t].back();
- a[1 - t].pop_back();
- } else {
- ans = a[t].front();
- a[t].pop_front();
- }
- return ans;
- }
- void close(int t) {
- use[1 - t] = true;
- }
- void open(int t) {
- use[1 - t] = 0;
- while (a[1 - t].size() < a[t].size()) {
- a[1 - t].push_back(a[t].back());
- a[t].pop_back();
- }
- while (a[1 - t].size() - a[t].size() > 1) {
- a[t].push_back(a[1 - t].back());
- a[1 - t].pop_back();
- }
- }
- int main() {;
- int n, to = 0;
- char c;
- scanf("%d\n", &n);
- while (n--) {
- scanf("%c", &c);
- if (c == 'a') {
- to = (to + 1) % 10;
- add(0, to);
- } else if (c == 'b') {
- to = (to + 1) % 10;
- add(1, to);
- } else if (c == 'A') {
- printf("%c", char(get(0) + '0'));
- } else if (c == 'B') {
- printf("%c", char(get(1) + '0'));
- } else if (c == '>') {
- close(0);
- } else if (c == ']') {
- close(1);
- } else if (c == '<') {
- open(0);
- } else if (c == '[') {
- open(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement