-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj_10828.cpp
More file actions
52 lines (50 loc) · 1005 Bytes
/
boj_10828.cpp
File metadata and controls
52 lines (50 loc) · 1005 Bytes
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
//<10828>번 : <스택>
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
stack<int> s;
int N, e;
string cmd;
cin >> N;
for(int i = 0; i < N; i++)
{
cin >> cmd;
if(cmd == "push")
{
cin >> e;
s.push(e);
}
if(cmd == "pop")
{
if(s.empty())
{
cout << -1 << '\n';
continue;
}
cout << s.top() << '\n';
s.pop();
}
if(cmd == "size")
{
cout << s.size() << '\n';
}
if(cmd == "empty")
{
if(s.empty())
cout << 1 << '\n';
else
cout << 0 << '\n';
}
if(cmd == "top")
{
if(s.empty() == false)
cout << s.top() << '\n';
else
cout << -1 << '\n';
}
}
return 0;
}