-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack10828_2.cpp
More file actions
64 lines (60 loc) · 882 Bytes
/
stack10828_2.cpp
File metadata and controls
64 lines (60 loc) · 882 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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main(void)
{
int n;
cin >> n;
stack<int> st;
string str;
while (n--)
{
cin >> str;
if (str == "push")
{
int num;
cin >> num;
st.push(num);
}
else if (str == "pop")
{
if (!st.empty())
{
cout << st.top() << endl;
st.pop();
}
else
{
cout << "-1" << endl;
}
}
else if (str == "size")
{
cout << st.size() << endl;
}
else if (str == "empty")
{
if (st.empty())
{
cout << "-1" << endl;
}
else
{
cout << "0" << endl;
}
}
else if (str == "top")
{
if (!st.empty())
{
cout << st.top() << endl;
}
else
{
cout << "-1" << endl;
}
}
}
return 0;
}