Advertisement
Romanchenko

Untitled

Dec 4th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #pragma GCC optimize ("O3")
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     //freopen("in.txt", "r", stdin);
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(0);
  10.     cout.tie(0);
  11.     int n;
  12.     cin >> n;
  13.     int idx = 1;
  14.    
  15.     deque<int> a;
  16.     deque<int> b;
  17.  
  18.     for (int i = 0; i < n; ++i) {
  19.         char ch;
  20.         cin >> ch;
  21.         if (ch == 'a') {
  22.             a.push_back((idx++) % 10);
  23.         }
  24.         if (ch == 'b') {
  25.             b.push_back((idx++)% 10);
  26.         }
  27.         if (ch == 'A') {
  28.             cout << a.front();
  29.             a.pop_front();
  30.         }
  31.         if (ch == 'B') {
  32.             cout << b.front();
  33.             b.pop_front();
  34.         }
  35.         if (ch == '>') {
  36.             while (a.size() > 0) {
  37.                 b.push_back(a.back());
  38.                 a.pop_back();
  39.             }
  40.         }
  41.         if (ch == '<') {
  42.             while ((int)b.size() - 1 >= (int)a.size() + 1) {
  43.                 a.push_back(b.back());
  44.                 b.pop_back();
  45.             }
  46.         }
  47.         if (ch == ']') {
  48.             while (!b.empty()) {
  49.                 a.push_back(b.back());
  50.                 b.pop_back();
  51.             }
  52.         }
  53.         if (ch == '[') {
  54.             while ((int)a.size() - 1 >= (int)b.size() + 1) {
  55.                 b.push_back(a.back());
  56.                 a.pop_back();
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement