-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask07-transform.c
104 lines (91 loc) · 1.41 KB
/
task07-transform.c
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
/*
ID: zltsang1
LANG: C
TASK: transform
*/
#include <stdio.h>
int nt;
char pbf[10][10]={0},paf[10][10]={0},pt[10][10]={0},pt2[10][10]={0};
void ref(){
int i,j;
char t;
for(i=0;i<nt;i++){
for(j=0;j<nt/2;j++){
t=pt[i][j];pt[i][j]=pt[i][nt-j-1];pt[i][nt-j-1]=t;
}
}
}
int ide(){
int i,j;
for(i=0;i<nt;i++){
for(j=0;j<nt;j++){
if(paf[i][j]!=pt[i][j])return 0;
}
}
return 1;
}
void rot90(int t){
int i,j,k;
for(k=0;k<t;k++){
for(i=0;i<nt;i++){
for(j=0;j<nt;j++){
pt2[j][nt-1-i]=pt[i][j];
}
}
for(i=0;i<nt;i++){
for(j=0;j<nt;j++){
pt[i][j]=pt2[i][j];
}
}
}
}
void cpy(){
int i,j;
for(i=0;i<nt;i++){
for(j=0;j<nt;j++){
pt[i][j]=pbf[i][j];
}
}
}
main () {
FILE *fin = fopen ("transform.in", "r");
FILE *fout = fopen ("transform.out", "w");
int a, b;
int i,j,k;
char ln[10];
fscanf (fin, "%d", &nt);
for(i=0;i<nt;i++){
fscanf(fin, "%s", ln);
for(j=0;j<nt;j++)pbf[i][j]=ln[j];
}
for(i=0;i<nt;i++){
fscanf(fin, "%s", ln);
for(j=0;j<nt;j++)pt[i][j]=paf[i][j]=ln[j];
}
for(k=1;k<4;k++){
cpy();
rot90(k);
if(ide()){
fprintf (fout, "%d\n", k);exit(0);
}
}
cpy();
ref();
if(ide()){
fprintf (fout, "%d\n", 4);exit(0);
}
for(k=1;k<4;k++){
cpy();
ref();
rot90(k);
if(ide()){
fprintf (fout, "%d\n", 5);exit(0);
}
}
cpy();
if(ide()){
fprintf (fout, "%d\n", 6);exit(0);
}
fprintf (fout, "%d\n", 7);
exit (0);
}