forked from AbhJ/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADAQUEUE.cpp
77 lines (71 loc) · 1.59 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
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <set>
#include <map>
//#include <unordered_map>
#include <utility>
#include <cassert>
#include <iomanip>
#include <ctime>
using namespace std;
const int me = 100025;
int q, x;
bool rev;
char type[10];
deque<int> Q;
int main(int argc, const char * argv[]) {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
scanf("%d", &q);
while(q --){
scanf(" %s", type);
if(type[0] == 't'){
scanf("%d", &x);
if(!rev)
Q.push_front(x);
else Q.push_back(x);
}
else if(type[0] == 'p'){
scanf("%d", &x);
if(!rev)
Q.push_back(x);
else Q.push_front(x);
}
else if(type[0] == 'r'){
rev ^= 1;
}
else if(type[0] == 'b'){
if(Q.empty())
puts("No job for Ada?");
else if(!rev){
printf("%d\n", Q.back());
Q.pop_back();
}
else{
printf("%d\n", Q.front());
Q.pop_front();
}
}
else{
if(Q.empty())
puts("No job for Ada?");
else if(!rev){
printf("%d\n", Q.front());
Q.pop_front();
}
else{
printf("%d\n", Q.back());
Q.pop_back();
}
}
}
return 0;
}