-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path744.cpp
More file actions
136 lines (112 loc) · 1.84 KB
/
744.cpp
File metadata and controls
136 lines (112 loc) · 1.84 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*****************************************
* (This comment block is added by the Judge System)
* Submission ID: 67240
* Submitted at: 2018-10-18 15:24:33
*
* User ID: 539
* Username: 55211931
* Problem ID: 744
* Problem Name: Stack Shuffling
*/
#include <iostream>
using namespace std;
class StackArray {
private:
int top = -1;
int capacity = 3000;
int num[3000];
public:
void Push(int y);
void Pop();
bool IsEmpty();
int getTop();
bool Check(int b[], int bSize);
void Back(int t);
};
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];
}
void StackArray::Back(int t)
{
top = t - 1;
}
bool StackArray::Check(int b[], int bSize)
{
StackArray S;
int i = 0;
bool state = true;
while (state && i < bSize)
{
while (!IsEmpty() && getTop() != b[i] && S.getTop() != b[i])
{
S.Push(getTop());
Pop();
}
if (getTop() == b[i])
{
Pop();
}
else if (S.getTop() == b[i])
{
S.Pop();
}
else
{
state = false;
return state;
}
i++;
}
return state;
}
int main() {
int times;
cin >> times;
for (int i = 0;i < times;i++)
{
StackArray A;
int arrSize;
cin >> arrSize;
for (int i = 0;i < arrSize;i++)
{
int a;
cin >> a;
A.Push(a);
}
int checkTimes;
cin >> checkTimes;
for (int i = 0;i < checkTimes;i++)
{
int b[3000];
for (int i = 0;i < arrSize;i++)
{
cin >> b[i];
}
if (A.Check(b, arrSize))
{
cout << "Aye" << endl;
}
else
{
cout << "Impossible" << endl;
}
A.Back(arrSize);
}
}
return 0;
}