-
Notifications
You must be signed in to change notification settings - Fork 2
/
10085.cpp
54 lines (47 loc) · 1.11 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
#include<stdio.h>
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 kases, f = 1, i, z;
//freopen("c:\\h.txt","r",stdin);
scanf("%d",&kases);
while(kases--) {
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;
}