-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj10866.cpp
More file actions
95 lines (88 loc) · 1.33 KB
/
boj10866.cpp
File metadata and controls
95 lines (88 loc) · 1.33 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
#include<iostream>
#include<string>
using namespace std;
int query;
class Deque{
public:
int ar[10001] = {}, size = 0;
void PushFront(int x){
if(size>0){
for(int i = size; i > 0; i--)
ar[i] = ar[i-1];
}
ar[0] = x;
size++;
}
void PushBack(int x){
ar[size] = x;
size++;
}
void PopFront(){
if(size==0){
cout << "-1\n";
return;
}
cout << ar[0] << '\n';
for(int i = 0; i < size; i++)
ar[i] = ar[i+1];
size--;
}
void PopBack(){
if(size==0){
cout << "-1\n";
return;
}
cout << ar[size-1] << '\n';
size--;
}
void Size(){
cout << size << '\n';
}
void Empty(){
cout << (size == 0 ? 1 : 0) << '\n';
}
void Front(){
if(size==0) cout << "-1\n";
else cout << ar[0] << '\n';
}
void Back(){
if(size==0) cout << "-1\n";
else cout << ar[size-1] << '\n';
}
};
int main()
{
scanf("%d", &query);
Deque Dq;
for(int i = 0; i < query; i++){
int X;
string Q;
cin >> Q;
if(Q == "push_front"){
cin >> X;
Dq.PushFront(X);
}
if(Q == "push_back"){
cin >> X;
Dq.PushBack(X);
}
if(Q == "pop_front"){
Dq.PopFront();
}
if(Q == "pop_back"){
Dq.PopBack();
}
if(Q == "size"){
Dq.Size();
}
if(Q == "empty"){
Dq.Empty();
}
if(Q == "front"){
Dq.Front();
}
if(Q == "back"){
Dq.Back();
}
}
}