Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- #include <iostream>
- #include <vector>
- #include <set>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <conio.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- const long double PI = acos(-1.0);
- const ld eps = 1e-12;
- const int INF = 2147483647;
- const ll LLINF = 9223372036854775807LL;
- const int MAX = 1000000;
- const int MAXPRIMES = 3163;
- #define mp make_pair
- typedef bool TABool[MAX];
- deque<int> v1, v2;
- bool normal = true;
- void push_f_right(int value) {
- if (normal)
- v2.push_front(value);
- else
- v1.push_front(value);
- }
- void push_b_left(int value) {
- if (normal)
- v1.push_back(value);
- else
- v2.push_back(value);
- }
- void push_b_right(int value) {
- if (normal)
- v2.push_back(value);
- else
- v1.push_back(value);
- }
- void pop_f_right() {
- if (normal)
- v2.pop_front();
- else
- v1.pop_front();
- }
- void pop_b_left() {
- if (normal)
- v1.pop_back();
- else
- v2.pop_back();
- }
- void pop_b_right() {
- if (normal)
- v2.pop_back();
- else
- v1.pop_back();
- }
- int v_first(bool left) {
- if (left == normal)
- return v1.front();
- else
- return v2.front();
- }
- int v_last(bool left) {
- if (left == normal)
- return v1.back();
- else
- return v2.back();
- }
- void v_swap() {
- normal = !normal;
- }
- int v_getsize(bool left) {
- if (left == normal)
- return v1.size();
- else
- return v2.size();
- }
- void v_print(bool left) {
- if (left == normal) {
- for (int i = 0; i < v1.size(); i++)
- printf("%d ", v1[i]);
- }
- else {
- for (int i = 0; i < v2.size(); i++)
- printf("%d ", v2[i]);
- }
- }
- int main()
- {
- freopen("kenobi.in", "r", stdin);
- freopen("kenobi.out", "w", stdout);
- int n;
- scanf("%d\n", &n);
- for (int i = 0; i < n; i++) {
- string s;
- cin >> s;
- if (s == "add") {
- int num;
- scanf("%d\n", &num);
- push_b_right(num);
- if (v_getsize(false) - v_getsize(true) > 1) {
- int temp = v_first(false);
- push_b_left(temp);
- pop_f_right();
- }
- }
- else if (s == "take") {
- if (v_getsize(false) > 0) {
- pop_b_right();
- if (v_getsize(true) > v_getsize(false)) {
- int temp = v_last(true);
- pop_b_left();
- push_f_right(temp);
- }
- }
- }
- else {
- v_swap();
- if (v_getsize(true) > v_getsize(false)) {
- int temp = v_last(true);
- pop_b_left();
- push_f_right(temp);
- }
- }
- }
- printf("%d\n", v1.size() + v2.size());
- v_print(true);
- v_print(false);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment