USACO 1.2 transform

/*
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值