-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPOJ-ADAQUEUE.cpp
More file actions
73 lines (67 loc) · 1.38 KB
/
SPOJ-ADAQUEUE.cpp
File metadata and controls
73 lines (67 loc) · 1.38 KB
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
deque<int> jobs;
int n;
int reverse = 1;
scanf("%d", &n);
char s[50];
for(int i = 0; i < n; i++){
scanf(" %s", s);
if(reverse == 1){
if(s[0] == 'f'){
if(jobs.empty()) printf("No job for Ada?\n");
else{
printf("%d\n", jobs.front());
//cout << jobs.front() << endl;
jobs.pop_front();
}
}else if(s[0] == 'b'){
if(jobs.empty()) printf("No job for Ada?\n");
else{
printf("%d\n", jobs.back());
//cout << jobs.back() << endl;
jobs.pop_back();
}
}else if(s[0] == 't'){
int temp;
scanf("%d", &temp);
jobs.push_front(temp);
}else if(s[0] == 'p'){
int temp;
scanf("%d", &temp);
jobs.push_back(temp);
}else{
reverse = 0;
}
}else{
if(s[0] == 'f'){
if(jobs.empty()) printf("No job for Ada?\n");
else{
printf("%d\n", jobs.back());
//cout << jobs.front() << endl;
jobs.pop_back();
}
}else if(s[0] == 'b'){
if(jobs.empty()) printf("No job for Ada?\n");
else{
printf("%d\n", jobs.front());
//cout << jobs.back() << endl;
jobs.pop_front();
}
}else if(s[0] == 't'){
int temp;
scanf("%d", &temp);
jobs.push_back(temp);
}else if(s[0] == 'p'){
int temp;
scanf("%d", &temp);
jobs.push_front(temp);
}else{
reverse = 1;
}
}
}
return 0;
}