-
Notifications
You must be signed in to change notification settings - Fork 0
/
스택 2.cc
61 lines (51 loc) · 1.09 KB
/
스택 2.cc
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
#include <iostream>
#include <stack>
using namespace std;
void ans(){
int N;
cin >> N;
stack<int> st;
for(int i=0; i < N; i++){
int oper;
cin >> oper;
if(oper == 1){
int X;
cin >> X;
st.push(X);
}
else if(oper == 2){
if(st.empty()){
cout << -1 << "\n";
}
else{
cout << st.top() << "\n";
st.pop();
}
}
else if(oper == 3){
cout << st.size() << "\n";
}
else if(oper == 4){
if(st.empty()){
cout << 1 << "\n";
}
else{
cout << 0 << "\n";
}
}
else if(oper == 5){
if(st.empty()){
cout << -1 << "\n";
}
else{
cout << st.top() << "\n";
}
}
}
}
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
ans();
return 0;
}