Guest User

Untitled

a guest
Nov 17th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.54 KB | None | 0 0
  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  3.     #include <string>
  4.     #include <iostream>
  5.     #include <vector>
  6.     #include <set>
  7.     #include <math.h>
  8.     #include <queue>
  9.     #include <stack>
  10.     #include <conio.h>
  11.     using namespace std;
  12.      
  13.     typedef long long ll;
  14.     typedef long double ld;
  15.      
  16.     const long double PI = acos(-1.0);
  17.     const ld eps = 1e-12;
  18.     const int INF = 2147483647;
  19.     const ll LLINF = 9223372036854775807LL;
  20.     const int MAX = 1000000;
  21.     const int MAXPRIMES = 3163;
  22.      
  23.     #define mp make_pair
  24.      
  25.     typedef bool TABool[MAX];
  26.      
  27.     deque<int> v1, v2;
  28.     bool normal = true;
  29.      
  30.     void push_f_right(int value) {
  31.         if (normal)
  32.             v2.push_front(value);
  33.         else
  34.             v1.push_front(value);
  35.     }
  36.     void push_b_left(int value) {
  37.         if (normal)
  38.             v1.push_back(value);
  39.         else
  40.             v2.push_back(value);
  41.     }
  42.     void push_b_right(int value) {
  43.         if (normal)
  44.             v2.push_back(value);
  45.         else
  46.             v1.push_back(value);
  47.     }
  48.     void pop_f_right() {
  49.         if (normal)
  50.             v2.pop_front();
  51.         else
  52.             v1.pop_front();
  53.     }
  54.     void pop_b_left() {
  55.         if (normal)
  56.             v1.pop_back();
  57.         else
  58.             v2.pop_back();
  59.     }
  60.     void pop_b_right() {
  61.         if (normal)
  62.             v2.pop_back();
  63.         else
  64.             v1.pop_back();
  65.     }
  66.     int v_first(bool left) {
  67.         if (left == normal)
  68.             return v1.front();
  69.         else
  70.             return v2.front();
  71.     }
  72.     int v_last(bool left) {
  73.         if (left == normal)
  74.             return v1.back();
  75.         else
  76.             return v2.back();
  77.     }
  78.     void v_swap() {
  79.         normal = !normal;
  80.     }
  81.     int v_getsize(bool left) {
  82.         if (left == normal)
  83.             return v1.size();
  84.         else
  85.             return v2.size();
  86.     }
  87.     void v_print(bool left) {
  88.         if (left == normal) {
  89.             for (int i = 0; i < v1.size(); i++)
  90.                 printf("%d ", v1[i]);
  91.         }
  92.         else {
  93.             for (int i = 0; i < v2.size(); i++)
  94.                 printf("%d ", v2[i]);
  95.         }
  96.     }
  97.      
  98.     int main()
  99.     {
  100.         freopen("kenobi.in", "r", stdin);
  101.         freopen("kenobi.out", "w", stdout);
  102.      
  103.         int n;
  104.         scanf("%d\n", &n);
  105.         for (int i = 0; i < n; i++) {
  106.             string s;
  107.             cin >> s;
  108.             if (s == "add") {
  109.                 int num;
  110.                 scanf("%d\n", &num);
  111.                 push_b_right(num);
  112.                 if (v_getsize(false) - v_getsize(true) > 1) {
  113.                     int temp = v_first(false);
  114.                     push_b_left(temp);
  115.                     pop_f_right();
  116.                 }
  117.             }
  118.             else if (s == "take") {
  119.                 if (v_getsize(false) > 0) {
  120.                     pop_b_right();
  121.                     if (v_getsize(true) > v_getsize(false)) {
  122.                         int temp = v_last(true);
  123.                         pop_b_left();
  124.                         push_f_right(temp);
  125.                     }
  126.                 }
  127.             }
  128.             else {
  129.                 v_swap();
  130.                 if (v_getsize(true) > v_getsize(false)) {
  131.                     int temp = v_last(true);
  132.                     pop_b_left();
  133.                     push_f_right(temp);
  134.                 }
  135.             }
  136.         }
  137.         printf("%d\n", v1.size() + v2.size());
  138.         v_print(true);
  139.         v_print(false);
  140.         return 0;
  141.     }
Advertisement
Add Comment
Please, Sign In to add comment