forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10085.cpp
74 lines (70 loc) · 1.2 KB
/
10085.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
#include <bits/stdc++.h>
using namespace std;
char com[9][45] = {"RRDLLURRDDLLURDLUURRDLURDDLLUUR",
"LDRRULLDDRRULDRUULLDRULDDRRUULL",
"LLDRRULLDDRRULDRUULLDRULDDRRUUL",
"RRULLDDRRULULDDRRULULDDRRUULLDD",
"LURRDLLURRDLLURDDLURDRULLURRDL",
"LLURRDDLLURURDDLLURURDDLLUURRDD",
"RRULLURDDRUULDDLUURDRDLLURRDLLU",
"LURRDLLUURRDLURDDLLURDLUURRDDLL",
"LLURRULDDLUURDDRUULDLDRRULLDRRU"};
int A[12];
void Cal(int z)
{
int i, j, p;
p = z;
for (i = 0; com[z][i]; i++)
{
switch (com[z][i])
{
case 'L':
A[p] = A[p - 1];
A[p - 1] = 0;
p--;
break;
case 'R':
A[p] = A[p + 1];
A[p + 1] = 0;
p++;
break;
case 'U':
A[p] = A[p - 3];
A[p - 3] = 0;
p -= 3;
break;
case 'D':
A[p] = A[p + 3];
A[p + 3] = 0;
p += 3;
break;
}
}
p = 0;
for (i = 0; i < 3; i++)
{
printf("%d", A[p++]);
for (j = 1; j < 3; j++)
printf(" %d", A[p++]);
printf("\n");
}
}
int main()
{
int T, f = 1, i, z;
scanf("%d", &T);
while (T--)
{
for (i = 0; i < 9; i++)
{
scanf("%d", &A[i]);
if (A[i] == 0)
z = i;
}
printf("Puzzle #%d\n", f++);
Cal(z);
puts(com[z]);
printf("\n");
}
return 0;
}