-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10866.cpp
77 lines (76 loc) · 1.32 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
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <deque>
#pragma warning(disable:4996)
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
deque<int> a;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
char cmd[10];
int tmp;
cin >> cmd;
if (!strcmp(cmd, "push_back")) {
cin >> tmp;
a.push_back(tmp);
}
else if (!strcmp(cmd, "push_front")) {
cin >> tmp;
a.push_front(tmp);
}
else if (!strcmp(cmd, "pop_front")) {
if (a.empty() != true) {
printf("%d\n", a.front());
a.pop_front();
}
else {
printf("-1\n");
}
}
else if (!strcmp(cmd, "pop_back")) {
if (a.empty() != true) {
printf("%d\n", a.back());
a.pop_back();
}
else {
printf("-1\n");
}
}
else if (!strcmp(cmd, "size")) {
printf("%d\n", a.size());
}
else if (!strcmp(cmd, "empty")) {
if (a.empty() != true) {
printf("0\n");
}
else {
printf("1\n");
}
}
else if (!strcmp(cmd, "front")) {
if (a.empty() != true) {
printf("%d\n", a.front());
}
else {
printf("-1\n");
}
}
else if (!strcmp(cmd, "back")) {
if (a.empty() != true) {
printf("%d\n", a.back());
}
else {
printf("-1\n");
}
}
}
return 0;
}