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