-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathw3_p2.cpp
More file actions
46 lines (38 loc) · 1004 Bytes
/
Copy pathw3_p2.cpp
File metadata and controls
46 lines (38 loc) · 1004 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 <bits/stdc++.h>
#define total_top_num 4
using namespace std;
int main()
{
cin.tie(nullptr), ios::sync_with_stdio(false);
int command_num;
stack<int> tower[total_top_num];
cin >> command_num;
for (int i = 0; i < command_num; i++)
{
string command;
cin >> command;
if (command == "stack")
{
int tower_num, y;
cin >> tower_num >> y;
tower[tower_num - 1].push(y);
}
else if (command == "pop")
{
int tower_num;
cin >> tower_num;
if (!tower[tower_num - 1].empty())
tower[tower_num - 1].pop();
}
else if (command == "top")
{
int top_max = -1;
for (int i = 0; i < total_top_num; i++)
{
if (!tower[i].empty() && tower[i].top() > top_max)
top_max = tower[i].top();
}
cout << top_max << endl;
}
}
}