-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
62 lines (51 loc) · 961 Bytes
/
Copy pathstack.cpp
File metadata and controls
62 lines (51 loc) · 961 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
#include <C:\INCLUDE\stdc++.h>
using namespace std;
stack<int> s;
string functions[5] = {"push", "pop", "size", "empty", "top"};
int amount;
string temp;
int tempnum;
void act(int chosen){
if(chosen == 0){
cin >> tempnum;
s.push(tempnum);
}
if(chosen == 1){
if(s.size() != 0){
s.pop();
}
else{
cout << -1;
}
}
if(chosen == 2){
cout << s.size();
}
if(chosen == 3){
if(s.empty()){
cout << 1;
}
else{
cout << 0;
}
}
if(chosen == 4){
if(s.size() == 0){
cout << -1;
}
else{
cout << s.top();
}
}
}
int main(){
cin >> amount;
for(int i = 0; i < amount; i++){
cin >> temp;
for(int j = 0; j < 5; j++){
if(temp == functions[j]){
act(j);
}
}
}
}