-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10866.cpp
More file actions
100 lines (96 loc) · 1.32 KB
/
10866.cpp
File metadata and controls
100 lines (96 loc) · 1.32 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <string>
using namespace std;
int arr[40000];
int l = 20000, r = 20000;
void push_front(int num) {
arr[--l] = num;
}
void push_back(int num) {
arr[r++] = num;
}
void pop_front() {
if (l >= r) {
printf("-1\n");
}
else {
printf("%d\n", arr[l++]);
}
}
void pop_back() {
if (r <= l) {
printf("-1\n");
}
else {
printf("%d\n", arr[--r]);
}
}
void size() {
printf("%d\n", r - l);
}
void empty() {
if (r - l == 0) {
printf("%d\n", 1);
}
else {
printf("%d\n", 0);
}
}
void front() {
if (r - l == 0) {
printf("-1\n");
}
else {
printf("%d\n", arr[l]);
}
}
void back() {
if (r - l == 0) {
printf("-1\n");
}
else {
printf("%d\n", arr[r - 1]);
}
}
int main(void) {
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s == "push_back") {
int num;
scanf("%d", &num);
push_back(num);
}
else if (s == "push_front") {
int num;
scanf("%d", &num);
push_front(num);
}
else if (s == "pop_back") {
printf("\n");
pop_back();
}
else if (s == "pop_front") {
printf("\n");
pop_front();
}
else if (s == "size") {
printf("\n");
size();
}
else if (s == "empty") {
printf("\n");
empty();
}
else if (s == "front") {
printf("\n");
front();
}
else if (s == "back") {
printf("\n");
back();
}
}
}