/*
ID:zizz-zi1
LANG:C
TASK:transform
*/
#include <stdio.h>
#define MAXN 10
typedef struct board board;
struct board{
int n;
char a[MAXN][MAXN];
};
board whirl(board a)
{
board b;
b=a; //这里貌似必须这样写
int i,j;
for(i=0;i<a.n;i++)
for(j=0;j<a.n;j++){
b.a[j][a.n-i-1]=a.a[i][j];
}
return b;
}
board mirror(board a)
{
board b;
int i,j;
b=a;
for(i=0;i<a.n;i++)
for(j=0;j<a.n;j++){
b.a[i][a.n-j-1]=a.a[i][j];
}
return b;
}
int check(board a,board b)
{
int i,j;
for(i=0;i<a.n;i++)
for(j=0;j<a.n;j++){
if(a.a[i][j]!=b.a[i][j]) return 0;
}
return 1;
}
int main(void)
{
board whirl(board);
board mirror(board);
int i,j,n;
board a,b;
FILE *fin,*fout;
fin=fopen("transform.in","r");
fout=fopen("transform.out","w");
fscanf(fin,"%d\n",&n);
a.n=b.n=n;
for(i=0;i<n;i++)
fscanf(fin,"%s\n",&a.a[i]);
for(i=0;i<n;i++)
fscanf(fin,"%s\n",&b.a[i]);
if (check(whirl(a),b)) fprintf(fout,"1\n");
else
if(check(whirl(whirl(a)),b)) fprintf(fout,"2\n");
else
if(check(whirl(whirl(whirl(a))),b)) fprintf(fout,"3\n");
else
if(check(mirror(a),b)) fprintf(fout,"4\n");
else
if(check(whirl(mirror(a)),b)||check(whirl(whirl(mirror(a))),b)||check(whirl(whirl(whirl(mirror(a)))),b)) fprintf(fout,"5\n");
else
if(check(a,b)) fprintf(fout,"6\n");
else
fprintf(fout,"7\n");
fclose(fin);fclose(fout);
return 0;
}
USACO 1.2 transform
最新推荐文章于 2023-02-11 19:20:33 发布