forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828.cpp
More file actions
37 lines (36 loc) · 778 Bytes
/
10828.cpp
File metadata and controls
37 lines (36 loc) · 778 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
// Authored by : BaaaaaaaaaaarkingDog
// Co-authored by : -
// http://boj.kr/c792146f735b42559e8cb3bf21e61fa9
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
stack<int> S;
while(n--){ // n번 반복
string c;
cin >> c;
if(c=="push"){
int t;
cin >> t;
S.push(t);
}
else if(c=="pop"){
if(S.empty()) cout << -1 << '\n';
else{
cout << S.top() << '\n';
S.pop();
}
}
else if(c=="size")
cout << S.size() << '\n';
else if(c=="empty")
cout << (int)S.empty() << '\n';
else{ // top
if(S.empty()) cout << -1 << '\n';
else cout << S.top() << '\n';
}
}
}