-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10866.cpp
More file actions
63 lines (51 loc) · 932 Bytes
/
10866.cpp
File metadata and controls
63 lines (51 loc) · 932 Bytes
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
#include "stdafx.h"
#include <deque>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, m;
deque<int> d;
string s;
cin >> n;
while (n--) {
cin >> s;
if (s == "push_front") {
cin >> m;
d.push_front(m);
}
else if (s == "push_back") {
cin >> m;
d.push_back(m);
}
else if (s == "pop_front") {
if (d.empty()) cout << "-1" << endl;
else {
cout << d.front() << endl;
d.pop_front();
}
}
else if (s == "pop_back") {
if (d.empty()) cout << "-1" << endl;
else {
cout << d.back() << endl;
d.pop_back();
}
}
else if (s == "empty") {
cout << d.empty() << endl;
}
else if (s == "front") {
if (d.empty()) cout << "-1" << endl;
else cout << d.front() << endl;
}
else if (s == "back") {
if (d.empty()) cout << "-1" << endl;
else cout << d.back() << endl;
}
else {
cout << d.size() << endl;
}
}
return 0;
}