-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10866.cpp
More file actions
64 lines (57 loc) · 1.36 KB
/
Copy path10866.cpp
File metadata and controls
64 lines (57 loc) · 1.36 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
#include<iostream>
#include<deque>
#include<string>
using namespace std;
deque<int> dq;
string input;
int tmp=0;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int testcase=0;
cin>>testcase;
while(testcase--){
cin>>input;
if(input=="push_front"){
cin>>tmp;
dq.push_front(tmp);
}
else if(input=="push_back"){
cin>>tmp;
dq.push_back(tmp);
}
else if(input=="pop_front"){
if(dq.empty()) cout<<"-1"<<'\n';
else {
tmp=dq.front();
dq.pop_front();
cout<<tmp<<'\n';
}
}
else if(input=="pop_back"){
if(dq.empty()) cout<<"-1"<<'\n';
else {
tmp=dq.back();
dq.pop_back();
cout<<tmp<<'\n';
}
}
else if(input=="size"){
cout<<dq.size()<<'\n';
}
else if(input=="empty"){
if(dq.empty()) cout<<"1"<<'\n';
else cout<<"0"<<'\n';
}
else if(input=="front"){
if(dq.empty()) cout<<"-1"<<'\n';
else cout<<dq.front()<<'\n';
}
else if(input=="back"){
if(dq.empty()) cout<<"-1"<<'\n';
else cout<<dq.back()<<'\n';
}
}
return 0;
}