-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10828.c
37 lines (32 loc) · 787 Bytes
/
10828.c
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
#include <stdio.h>
#include <string.h>
int main() {
int int_n;
char string_command[10];
int int_arg;
int int_top = -1;
int stack[10000];
scanf("%d", &int_n);
for (int i = 0; i < int_n; i++) {
scanf("%s %d", string_command, &int_arg);
if (!strcmp(string_command, "push")) {
stack[int_top+++1] = int_arg;
}
else if (!strcmp(string_command, "pop")) {
if (int_top != -1)
printf("%d\n", stack[int_top--]);
else
printf("-1\n");
}else if (!strcmp(string_command, "size")) {
printf("%d\n", int_top + 1);
}else if (!strcmp(string_command, "empty")) {
int_top == -1 ? printf("1\n") : printf("0\n");
}else if (!strcmp(string_command, "top")) {
if (int_top != -1)
printf("%d\n", stack[int_top]);
else
printf("-1\n");
}
}
return 0;
}