Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int N = 1e6 + 5;
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0, 0};
- long long t, x;
- bool f;
- string s;
- deque<long long>dq;
- int main()
- {
- IO
- cin >> t;
- while (t--)
- {
- cin >> s;
- if (s[0] == 't')
- {
- cin >> x;
- if (f == 0)dq.push_front(x);
- else dq.push_back(x);
- }
- else if (s[0] == 'p')
- {
- cin >> x;
- if (f == 0)dq.push_back(x);
- else dq.push_front(x);
- }
- else if (s[0] == 'r')
- {
- // f = !f;
- // f = 1 - f;
- f ^= 1;
- }
- else if (dq.empty())
- {
- cout << "No job for Ada?\n";
- }
- else if (s[0] == 'f')
- {
- if (f == 0)
- {
- cout << dq.front() << '\n';
- dq.pop_front();
- }
- else
- {
- cout << dq.back() << '\n';
- dq.pop_back();
- }
- }
- else
- {
- if (f)
- {
- cout << dq.front() << '\n';
- dq.pop_front();
- }
- else
- {
- cout << dq.back() << '\n';
- dq.pop_back();
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment