-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathADAQUEUE.cpp
More file actions
57 lines (57 loc) · 1.56 KB
/
Copy pathADAQUEUE.cpp
File metadata and controls
57 lines (57 loc) · 1.56 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
// Ivan Carvalho
// Solution to https://www.spoj.com/problems/ADAQUEUE/
#include <cstdio>
#include <deque>
using namespace std;
deque<int> fila;
int estado, q;
char entrada[200];
int main() {
scanf("%d", &q);
while (q--) {
int davez;
scanf("%s", entrada);
if (entrada[0] == 'b') {
if (fila.empty()) {
printf("No job for Ada?\n");
} else {
if (estado == 0) {
printf("%d\n", fila.back());
fila.pop_back();
} else {
printf("%d\n", fila.front());
fila.pop_front();
}
}
} else if (entrada[0] == 'f') {
if (fila.empty()) {
printf("No job for Ada?\n");
} else {
if (estado == 1) {
printf("%d\n", fila.back());
fila.pop_back();
} else {
printf("%d\n", fila.front());
fila.pop_front();
}
}
} else if (entrada[0] == 'r')
estado = 1 - estado;
else if (entrada[0] == 'p') {
scanf("%d", &davez);
if (estado == 0) {
fila.push_back(davez);
} else {
fila.push_front(davez);
}
} else {
scanf("%d", &davez);
if (estado == 1) {
fila.push_back(davez);
} else {
fila.push_front(davez);
}
}
}
return 0;
}