-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10866.cpp
67 lines (65 loc) · 1.09 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
#include <bits/stdc++.h>
#define swap(a,b) (a)^=(b)^=(a)^=(b)
#define endl '\n'
using namespace std;
typedef long long lld;
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
deque<int> deq;
string s;
for(int i=0;i<n;i++)
{
cin>>s;
int tmp;
if(s=="push_back")
{
cin>>tmp;
deq.push_back(tmp);
}
else if(s=="push_front")
{
cin>>tmp;
deq.push_front(tmp);
}
else if(s=="front")
{
if(deq.empty()) cout<<-1<<endl;
else cout<<deq.front()<<endl;
}
else if(s=="back")
{
if(deq.empty()) cout<<-1<<endl;
else cout<<deq.back()<<endl;
}
else if(s=="pop_front")
{
if(deq.empty()) cout<<-1<<endl;
else
{
cout<<deq.front()<<endl;
deq.pop_front();
}
}
else if(s=="pop_back")
{
if(deq.empty()) cout<<-1<<endl;
else
{
cout<<deq.back()<<endl;
deq.pop_back();
}
}
else if(s=="size") cout<<deq.size()<<endl;
else if(s=="empty")
{
if(deq.empty()) cout<<1<<endl;
else cout<<0<<endl;
}
}
return 0;
}