-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828.cpp
More file actions
42 lines (35 loc) · 754 Bytes
/
10828.cpp
File metadata and controls
42 lines (35 loc) · 754 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
40
41
42
#include <iostream>
using namespace std;
int stack[10001];
int size=0;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
int stack[10001];
int s=0;
while(n--){
string o;
cin>>o;
if(o=="push"){
int k;
cin>>k;
stack[s]=k;
s++;
}
else if(o=="pop"){
if(s==0) cout<<-1<<"\n";
else{
cout<<stack[s-1]<<"\n";
s--;
}
}
else if(o=="size") cout<<s<<"\n";
else if(o=="empty") cout<<((s==0)?1:0)<<"\n";
else if(o=="top") {
if(s==0) cout<<-1<<"\n";
else cout<<stack[s-1]<<"\n";
}
}
}