-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (34 loc) · 805 Bytes
/
Copy pathmain.cpp
File metadata and controls
34 lines (34 loc) · 805 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>
#include <string>
#include <stack>
using namespace std;
stack<int> st;
int N;
string cmd;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
while(N--) {
cin >> cmd;
if(cmd == "push") {
int n;
cin >> n;
st.push(n);
} else if(cmd == "top") {
if(st.empty()) cout << "-1\n";
else cout << st.top() << '\n';
} else if(cmd == "size") {
cout << st.size() << '\n';
} else if(cmd == "pop") {
if(st.empty()) cout << "-1\n";
else {
cout << st.top() << '\n';
st.pop();
}
} else if(cmd == "empty") {
cout << st.empty() << '\n';
}
}
return 0;
}