-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10828.cpp
46 lines (45 loc) ยท 982 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>
using namespace std;
int main(){
stack<int> s;
int index;
cin>>index;
for (int i=0; i<index; i++){
string order;
cin>>order;
if (order == "push"){
int num;
cin>>num;
s.push(num);
}
else if (order == "pop"){
if (!s.empty()){
cout<<s.top()<<endl;
s.pop();
}
else{
cout<<"-1"<<endl;
}
}
else if (order == "size"){
cout<<s.size()<<endl;
}
else if (order == "empty"){
if (!s.empty()){
cout<<"0"<<endl;
}
else{
cout<<"1"<<endl;
}
}
else if (order == "top"){
if (!s.empty()){
cout<<s.top()<<endl;
}
else{
cout<<"-1"<<endl;
}
}
}
}