-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10828.cpp
46 lines (41 loc) · 942 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
#include <iostream>
#include <stack>
#include <string>
using namespace std;
stack<int> st;
int main(){
int n;
cin>>n;
string str;
int num, flag;
for(int i=1; i<=n; i++){
cin>>str;
if(str.compare("push")==0){
flag=1;
cin>>num;
st.push(num);
}
else if(str.compare("pop")==0){
if(st.empty()) cout<<"-1"<<endl;
else{
int temp = st.top();
st.pop();
cout<<temp<<endl;
}
}
else if(str.compare("size")==0){
cout<<st.size()<<endl;
}
else if(str.compare("empty")==0){
cout<<st.empty()<<endl;
}
else if(str.compare("top")==0){
if(st.empty()) cout<<"-1"<<endl;
else{
int temp = st.top();
cout<<temp<<endl;
}
}
}
return 0;
}