-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[백준 10866] 덱.cpp
77 lines (74 loc) · 1.29 KB
/
[백준 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
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 <deque>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
deque <int> d;
int n; cin >> n;
for (int i = 0; i < n; ++i) {
string tmp; cin >> tmp;
if (tmp[0] == 'p') {
// push_front / push_back / pop_front / pop_back
if (tmp[1] == 'u') {
// push~
int m; cin >> m;
if (tmp[5] == 'f') {
d.push_front(m);
}
else {
d.push_back(m);
}
}
else {
// pop~
if (tmp[4] == 'f') {
if (d.empty()) {
cout << -1 << '\n';
}
else {
cout << d.front() << '\n';
d.pop_front();
}
}
else {
if (d.empty()) {
cout << -1 << '\n';
}
else {
cout << d.back() << '\n';
d.pop_back();
}
}
}
}
else if (tmp[0] == 's') {
// size
cout << d.size() << '\n';
}
else if (tmp[0] == 'e') {
// empty
cout << d.empty() << '\n';
}
else if (tmp[0] == 'f') {
// front
if (d.empty()) {
cout << -1 << '\n';
}
else {
cout << d.front() << '\n';
}
}
else if (tmp[0] == 'b') {
// back
if (d.empty()) {
cout << -1 << '\n';
}
else {
cout << d.back() << '\n';
}
}
}
return 0;
}