-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path745.cpp
More file actions
104 lines (91 loc) · 1.46 KB
/
745.cpp
File metadata and controls
104 lines (91 loc) · 1.46 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*****************************************
* (This comment block is added by the Judge System)
* Submission ID: 67326
* Submitted at: 2018-10-18 22:03:36
*
* User ID: 539
* Username: 55211931
* Problem ID: 745
* Problem Name: Poker
*/
#include <iostream>
using namespace std;
class StackArray {
private:
int top = -1;
int num[20000];
public:
void Push(int y);
void Pop();
bool IsEmpty();
int getTop();
};
void StackArray::Push(int y) {
num[++top] = y;
}
void StackArray::Pop() {
top--;
}
bool StackArray::IsEmpty() {
if (top == -1) {
return true;
}
else {
return false;
}
return (top == -1);
}
int StackArray::getTop() {
return num[top];
}
int main()
{
int caseNum;
cin >> caseNum;
for (int i = 0;i < caseNum;i++)
{
StackArray Poke;
int size;
cin >> size;
int max = 0;
for (int i = 0;i < size;i++)
{
int a;
cin >> a;
if (a > max)
{
max = a;
}
Poke.Push(max);
}
int operation;
cin >> operation;
for (int i = 0;i < operation;i++)
{
char oper;
cin >> oper;
switch (oper)
{
case 'm':
cout << Poke.getTop() << endl;
break;
case 'r':
Poke.Pop();
break;
case 'a':
int a;
cin >> a;
if (a > Poke.getTop())
{
Poke.Push(a);
}
else
{
Poke.Push(Poke.getTop());
}
break;
}
}
}
return 0;
}