-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (37 loc) · 718 Bytes
/
main.cpp
File metadata and controls
46 lines (37 loc) · 718 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
43
44
45
46
#include <stdio.h>
#include <stack>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n,push_a;
string command;
scanf_s("%d", &n);
stack<int> s;
for (int i = 0; i < n; i++) {
cin >> command;
if (command == "push") {
scanf_s("%d", &push_a);
s.push(push_a);
}
else if (command == "pop") {
if (s.empty()) cout << "-1" << endl;
else {
cout << s.top() << endl;
s.pop();
}
}
else if (command == "size") {
cout << s.size() << endl;
}
else if (command == "empty") {
cout << (s.empty() ? 1 : 0) << endl;
}
else if (command == "top") {
if (s.empty()) cout << "-1" << endl;
else cout << s.top() << endl;
}
}
}