-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828.cpp
More file actions
34 lines (32 loc) · 799 Bytes
/
10828.cpp
File metadata and controls
34 lines (32 loc) · 799 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
#include <iostream>
using namespace std;
int main(){
int Stack[10001] = {0,};
int n, idx = -1;
string str;
cin >> n;
for(int i = 0; i < n; i++){
cin >> str;
if(str == "push"){
int num;
cin >> num;
Stack[++idx] = num;
}
else if(str == "pop"){
if(idx == -1) cout << "-1" << endl;
else cout << Stack[idx--] << endl;
}
else if(str == "size"){
cout << idx + 1 << endl;
}
else if(str == "empty"){
if(idx == -1) cout << "1" << endl;
else cout << "0" << endl;
}
else if(str == "top"){
if(idx == -1) cout << "-1" << endl;
else cout << Stack[idx] << endl;
}
}
return 0;
}