Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define mp make_pair
  3. #define x first
  4. #define y second
  5. #define pb push_back
  6. using namespace std;
  7. typedef long long ll;
  8. typedef long double ld;
  9. deque<int> a[2];
  10. bool use[2];
  11. void add(int t, int x) {
  12. if (use[t]) {
  13. a[1 - t].push_front(x);
  14. } else {
  15. a[t].push_back(x);
  16. }
  17. }
  18.  
  19. int get(int t) {
  20. int ans;
  21. if (a[t].empty()) {
  22. ans = a[1 - t].back();
  23. a[1 - t].pop_back();
  24. } else {
  25. ans = a[t].front();
  26. a[t].pop_front();
  27. }
  28.  
  29. return ans;
  30. }
  31.  
  32. void close(int t) {
  33. use[1 - t] = true;
  34. }
  35.  
  36. void open(int t) {
  37. use[1 - t] = 0;
  38. while (a[1 - t].size() < a[t].size()) {
  39. a[1 - t].push_back(a[t].back());
  40. a[t].pop_back();
  41. }
  42.  
  43. while (a[1 - t].size() - a[t].size() > 1) {
  44. a[t].push_back(a[1 - t].back());
  45. a[1 - t].pop_back();
  46. }
  47. }
  48.  
  49.  
  50. int main() {;
  51. int n, to = 0;
  52. char c;
  53. scanf("%d\n", &n);
  54. while (n--) {
  55. scanf("%c", &c);
  56. if (c == 'a') {
  57. to = (to + 1) % 10;
  58. add(0, to);
  59. } else if (c == 'b') {
  60. to = (to + 1) % 10;
  61. add(1, to);
  62. } else if (c == 'A') {
  63. printf("%c", char(get(0) + '0'));
  64. } else if (c == 'B') {
  65. printf("%c", char(get(1) + '0'));
  66. } else if (c == '>') {
  67. close(0);
  68. } else if (c == ']') {
  69. close(1);
  70. } else if (c == '<') {
  71. open(0);
  72. } else if (c == '[') {
  73. open(1);
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement