-
Notifications
You must be signed in to change notification settings - Fork 1
/
1517.cpp
143 lines (138 loc) · 3.07 KB
/
1517.cpp
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
137
138
139
140
141
142
143
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
class RubikCube {
public:
static int faces[6][3][3];
static int op[6][54];
char data[54];
void input() {
for(int i = 0; i < 54; ++i) {
char tmp[8];
scanf("%s", tmp);
data[i] = tmp[0];
}
}
void operate(char cmd[]) {
int idx = cmd[1] - '1';
char newdata[54];
for(int i = 0; i < 54; ++i) {
if(cmd[0] == '+')
newdata[i] = data[op[idx][i]];
else
newdata[op[idx][i]] = data[i];
}
for(int i = 0; i < 54; ++i)
data[i] = newdata[i];
}
bool check() {
for(int k = 0; k < 6; ++k) {
for(int i = 0; i < 3; ++i)
for(int j = 0; j < 3; ++j) {
if(i == 0 && j == 0)
continue;
if(data[faces[k][i][j]] != data[faces[k][0][0]])
return false;
}
}
return true;
}
void print() {
for(int i = 0; i < 6; ++i) {
for(int j = 0; j < 3; ++j) {
for(int k = 0; k < 3; ++k) {
putchar(data[faces[i][j][k]]);
}
putchar('\n');
}
putchar('\n');
}
}
};
int RubikCube::faces[6][3][3] = {
0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 21, 22, 23, 33, 34, 35,
12, 13, 14, 24, 25, 26, 36, 37, 38,
15, 16, 17, 27, 28, 29, 39, 40, 41,
18, 19, 20, 30, 31, 32, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53,
};
int RubikCube::op[6][54] = {
{
44, 1, 2, 32, 4, 5, 20, 7, 8,
33, 21, 9, 0, 13, 14, 15, 16, 17,
18, 19, 51, 34, 22, 10, 3, 25, 26,
27, 28, 29, 30, 31, 48, 35, 23, 11,
6, 37, 38, 39, 40, 41, 42, 43, 45,
12, 46, 47, 24, 49, 50, 36, 52, 53,
}
,
{
0, 1, 2, 3, 4, 5, 35, 23, 11,
9, 10, 45, 36, 24, 12, 6, 16, 17,
18, 19, 20, 21, 22, 46, 37, 25, 13,
7, 28, 29, 30, 31, 32, 33, 34, 47,
38, 26, 14, 8, 40, 41, 42, 43, 44,
39, 27, 15, 48, 49, 50, 51, 52, 53,
}
,
{
0, 1, 14, 3, 4, 26, 6, 7, 38,
9, 10, 11, 12, 13, 47, 39, 27, 15,
8, 19, 20, 21, 22, 23, 24, 25, 50,
40, 28, 16, 5, 31, 32, 33, 34, 35,
36, 37, 53, 41, 29, 17, 2, 43, 44,
45, 46, 42, 48, 49, 30, 51, 52, 18,
}
,
{
17, 29, 41, 3, 4, 5, 6, 7, 8,
2, 10, 11, 12, 13, 14, 15, 16, 53,
42, 30, 18, 1, 22, 23, 24, 25, 26,
27, 28, 52, 43, 31, 19, 0, 34, 35,
36, 37, 38, 39, 40, 51, 44, 32, 20,
45, 46, 47, 48, 49, 50, 9, 21, 33,
}
,
{
6, 3, 0, 7, 4, 1, 8, 5, 2,
12, 13, 14, 15, 16, 17, 18, 19, 20,
9, 10, 11, 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,
}
,
{
0, 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, 42, 43, 44,
33, 34, 35, 36, 37, 38, 39, 40, 41,
51, 48, 45, 52, 49, 46, 53, 50, 47,
}
};
int main() {
int t;
scanf("%d", &t);
while(t--) {
RubikCube rc;
rc.input();
while(1) {
char cmd[8];
scanf("%s", cmd);
if(strcmp(cmd, "0") == 0)
break;
rc.operate(cmd);
}
//rc.print();
if(rc.check()) {
printf("Yes, grandpa!\n");
}
else {
printf("No, you are wrong!\n");
}
}
return 0;
}