-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathADAQUEUE.cpp
40 lines (35 loc) · 1.01 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
/*
ad-hoc
difficulty: easy
date: 02/Mar/2020
by: @brpapa
*/
#include <iostream>
#include <deque>
using namespace std;
int main() {
deque<int> dq;
bool reversed = false;
int Q; cin >> Q;
while (Q--) {
string cmd; cin >> cmd;
if ((cmd == "back" && !reversed) || (cmd == "front" && reversed)) {
if (dq.empty()) cout << "No job for Ada?" << endl;
else { cout << dq.back() << endl; dq.pop_back(); }
}
else if ((cmd == "front" && !reversed) || (cmd == "back" && reversed)) {
if (dq.empty()) cout << "No job for Ada?" << endl;
else { cout << dq.front() << endl; dq.pop_front(); }
}
else if (cmd == "reverse") {
reversed = !reversed;
}
else if ((cmd == "push_back" && !reversed) || (cmd == "toFront" && reversed)) {
int n; cin >> n; dq.push_back(n);
}
else if ((cmd == "toFront" && !reversed) || (cmd == "push_back" && reversed)) {
int n; cin >> n; dq.push_front(n);
}
}
return 0;
}