-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_boj_10845.cpp
91 lines (79 loc) · 1.54 KB
/
12_boj_10845.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int arr[10000];
int n, pushNum;
char command[15];
int first=0;
int len=0;
void push(int pushNum) {
arr[len]=pushNum;
len++;
return;
}
void pop() {
if (!(len-first)) {
printf("-1\n");
return;
}
printf("%d\n", arr[first]);
first++;
return;
}
void size() {
printf("%d\n",len-first);
return;
}
void empty() {
if (!(len-first)) {
printf("1\n");
} else {
printf("0\n");
}
return;
}
void front() {
if (!(len-first)) {
printf("-1\n");
return;
}
printf("%d\n", arr[first]);
return;
}
void back() {
if (!(len-first)) {
printf("-1\n");
return;
}
printf("%d\n", arr[len-1]);
return;
}
int main() {
scanf("%d", &n);
for (int i=0; i<n; i++) {
scanf("%s", command);
// puts("");
// printf("%s\n", command);
// for (int j=0; j<len; j++) {
// printf("%d", arr[j]);
// }
// puts("");
if (!strcmp(command, "push")) {
scanf("%d", &pushNum);
push(pushNum);
} else if (!strcmp(command, "pop")) {
pop();
} else if (!strcmp(command, "size")) {
size();
} else if (!strcmp(command, "empty")) {
empty();
} else if (!strcmp(command, "front")) {
front();
} else if (!strcmp(command, "back")) {
back();
}
}
return 0;
}