-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboj10828.cpp
39 lines (37 loc) · 866 Bytes
/
boj10828.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
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0); cin.tie(0);
stack<int> s;
int k;
cin >> k;
string order;
for(int i=0;i<k;i++){
cin >> order;
if(!order.compare("push")){
int key;
cin >> key;
s.push(key);
}
else if(!order.compare("top")){
if(!s.empty())
cout << s.top() << "\n";
else
cout << -1 << "\n";
}
else if(!order.compare("size")){
cout << s.size() << "\n";
}
else if(!order.compare("empty")){
cout << s.empty() << "\n";
}
else{
if(!s.empty()){
cout << s.top()<<"\n";
s.pop();
}
else
cout << -1 << "\n";
}
}
}