-
Notifications
You must be signed in to change notification settings - Fork 0
/
7주차_과제2(10828).c
52 lines (43 loc) · 1 KB
/
7주차_과제2(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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#define MAX 100001
int stack[MAX];
int top = -1;
int main()
{
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++)
{
char input[10];
scanf("%s", input);
if (strcmp(input, "push") == 0)
{
int num;
scanf("%d", &num);
stack[++top] = num;
}
else if (strcmp(input, "pop") == 0)
{
if (top == -1) { printf("%d\n", -1); }
else { printf("%d\n", stack[top--]); }
}
else if (strcmp(input, "size") == 0)
{
printf("%d\n", top + 1);
}
else if (strcmp(input, "empty") == 0)
{
if (top == -1) { printf("%d\n", 1); }
else { printf("%d\n", 0); }
}
else if (strcmp(input, "top") == 0)
{
if (top == -1) { printf("-1\n"); }
else { printf("%d\n", stack[top]); }
}
else {}
}
return 0;
}