-
Notifications
You must be signed in to change notification settings - Fork 0
/
10866.cpp
47 lines (46 loc) · 955 Bytes
/
10866.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
#include <iostream>
#include <deque>
#include <string>
using namespace std;
int main() {
int n, x;
string input;
deque<int> dq;
cin >> n;
for(int i=0; i<n; i++) {
cin >> input;
if(input == "push_front") {
cin >> x;
dq.push_front(x);
}
else if(input == "push_back") {
cin >> x;
dq.push_back(x);
}
else if(input == "pop_front") {
if(dq.empty() == 1) cout << "-1\n";
else {
cout << dq.front() << "\n";
dq.pop_front();
}
}
else if(input == "pop_back") {
if(dq.empty() == 1) cout << "-1\n";
else {
cout << dq.back() << "\n";
dq.pop_back();
}
}
else if(input == "size") cout << dq.size() << "\n";
else if(input == "empty") cout << int(dq.empty()) << "\n";
else if(input == "front") {
if(dq.empty() == 0) cout << dq.front() << "\n";
else cout << "-1\n";
}
else if(input == "back") {
if(dq.empty() == 0) cout << dq.back() << "\n";
else cout << "-1\n";
}
}
return 0;
}