-
Notifications
You must be signed in to change notification settings - Fork 27
/
ADAQUEUE.cpp
64 lines (61 loc) · 1.12 KB
/
ADAQUEUE.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007LL
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
const int MAXN = 1e5+5;
int main(){
io;
int q;
cin >> q;
deque<int> dq;
int rev = 0;
while(q--){
string str;
cin >> str;
if(str == "back"){
if(dq.size() == 0)
cout << "No job for Ada?" << endl;
else{
if(rev%2 == 0){
cout << dq.back() << endl;
dq.pop_back();
}else{
cout << dq.front() << endl;
dq.pop_front();
}
}
}else if(str == "front"){
if(dq.size() == 0)
cout << "No job for Ada?" << endl;
else{
if(rev%2 == 0){
cout << dq.front() << endl;
dq.pop_front();
}else{
cout << dq.back() << endl;
dq.pop_back();
}
}
}else if(str == "reverse"){
rev++;
}
else if(str == "push_back"){
int x;
cin >> x;
if(rev%2 == 0){
dq.push_back(x);
}else
dq.push_front(x);
}else if(str == "toFront"){
int x;
cin >> x;
if(rev%2 == 0){
dq.push_front(x);
}else
dq.push_back(x);
}
}
return 0;
}