-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828_stack.cpp
More file actions
51 lines (45 loc) · 852 Bytes
/
10828_stack.cpp
File metadata and controls
51 lines (45 loc) · 852 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
47
48
49
50
51
#include <iostream>
#include <stack>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
stack<int> s;
string str;
int a;
for (int i = 0; i < N; i++)
{
cin >> str;
if (str == "push")
{
cin >> a;
s.push(a);
}
else if (str == "size")
{
cout << s.size() << endl;
}
else if (str == "empty")
{
cout << s.empty() ? 1 : 0;
cout << endl;
}
else
{
if (s.empty())
{
cout << -1 << endl;
}
else
{
cout << s.top() << endl;
if (str == "pop") s.pop();
}
}
}
return 0;
}