-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828.cpp
More file actions
39 lines (36 loc) · 802 Bytes
/
10828.cpp
File metadata and controls
39 lines (36 loc) · 802 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
38
39
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main()
{
io;
int N;
cin>>N;
stack<int> st;
for(int i=0;i<N;i++){
string s;
cin>>s;
if(s=="push"){
int n;
cin>>n;
st.push(n);
}else if(s=="top"){
if(!st.empty()){
cout<<st.top()<<'\n';
}else cout<<"-1\n";
}else if(s=="size"){
cout<<st.size()<<'\n';
}else if(s=="empty"){
cout<<st.empty()<<'\n';
}else if(s=="pop"){
if(!st.empty()){
cout<<st.top()<<'\n';
st.pop();
}else cout<<"-1\n";
}
}
return 0;
}