-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11_boj_10828.cpp
73 lines (63 loc) · 1.15 KB
/
11_boj_10828.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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
int arr[10000];
int len=0;
int n, pushNum;
char command[15];
void push(int pushNum) {
arr[len]=pushNum;
len++;
return;
}
void pop() {
if (len==0) {
printf("-1\n");
return;
}
printf("%d\n", arr[len-1]);
len--;
return;
}
void size() {
printf("%d\n", len);
return;
}
void empty() {
if (len == 0) {
printf("1\n");
} else {
printf("0\n");
}
return;
}
void top() {
if (len == 0) {
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);
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,"top")) {
top();
}
}
return 0;
}