-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10828.cpp
72 lines (69 loc) · 810 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
60
61
62
63
64
65
66
67
68
69
70
71
72
// 10828. 스택
// 2019.05.22
// 스택
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[10000];
int cnt = 0;
string s;
while (n>0)
{
n--;
cin >> s;
// push
if (s == "push")
{
int num;
cin >> num;
arr[++cnt] = num;
}
// pop
else if (s == "pop")
{
if (cnt != 0)
{
cout << arr[cnt] << endl;
cnt--;
}
else
{
cout << "-1" << endl;
}
}
// size
else if (s == "size")
{
cout << cnt << endl;
}
// empty
else if (s == "empty")
{
if (cnt == 0)
{
cout << "1" << endl;
}
else
{
cout << "0" << endl;
}
}
// top
else if (s == "top")
{
if (cnt != 0)
{
cout << arr[cnt] << endl;
}
else
{
cout << "-1" << endl;
}
}
}
return 0;
}