-
Notifications
You must be signed in to change notification settings - Fork 0
/
10828.cpp
59 lines (51 loc) · 836 Bytes
/
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
#include "stdio.h"
#include "string.h"
int stack[10000];
int top = -1;
bool empty(){
return top == -1;
}
void push(int n){
stack[++top] = n;
}
int pop(){
return stack[top--];
}
int get_size(){
return top+1;
}
int get_top(){
return stack[top];
}
int main(){
int n;
scanf("%d", &n);
while(n--){
char input[1000];
scanf("%s", input);
if(strcmp(input, "push") == 0){
int tmp;
scanf("%d", &tmp);
push(tmp);
}
else if(strcmp(input, "pop") == 0){
if(!empty())
printf("%d\n", pop());
else
printf("%d\n", -1);
}
else if(strcmp(input, "top") == 0){
if(!empty())
printf("%d\n", get_top());
else
printf("%d\n", -1);
}
else if(strcmp(input, "size") == 0){
printf("%d\n", get_size());
}
else if(strcmp(input, "empty") == 0){
printf("%d\n", empty());
}
}
return 0;
}