1.2 Transformations

 

不想再写下去了,对于这道题的模拟,我实在没什么好办法,在不断修改的过程中,bug也不断出现。这道题没AC,暂时搁在这里,心情不好!

 

 

/*
ID:y7276571
LANG: C
TASK: transform
*/
#include<stdio.h>
#include<string.h>
#define MAXN 10
char a[MAXN][MAXN], b[MAXN][MAXN], c[MAXN][MAXN], d[MAXN][MAXN];
int n;
int rotate(int t)
{
int i, j;
while(t--)
{
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
c[j][n-i-1] = a[i][j];
for(j = 0; j < n; j++) strcpy(a[j], c[j]);
}
for(j = 0; j < n; j++) strcpy(a[j], d[j]);
return 1;
}
int reflect()
{
int i, j;
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
c[i][j] = a[i][n-j-1];
return 1;
}
int nochange()
{
int i;
for(i = 0; i < n; i++)
if(strcmp(a[i], b[i]) != 0) return 0;
return 1;
}
int combine()
{
int i, j;
for(i = 1; i < 4; i++)
{
reflect();
for(j = 0; j < n; j++) strcpy(a[j], c[j]);
rotate(i);
if(check() == 1) return 1;
}
for(j = 0; j < n; j++) strcpy(a[j], d[j]);
return 0;
}
int check()
{
int i;
for(i = 0; i < n; i++)
if(strcmp(c[i], b[i]) != 0) return 0;
return 1;
}
int main(void)
{
freopen("transform.in", "r", stdin);
freopen("transform.out", "w", stdout);
int A = 7, i;
scanf("%d", &n);
for(i=0; i < n; i++) scanf("%s", a[i]);
for(i=0; i < n; i++) scanf("%s", b[i]);
for(i = 0; i < n; i++) strcpy(d[i], a[i]);
if(rotate(1) && check()) A = 1;
else if(rotate(2) && check()) A = 2;
else if(rotate(3) && check()) A = 3;
else if(reflect() && check()) A = 4;
else if(combine()) A = 5;
else if(nochange() && check()) A = 6;
printf("%d\n", A);
exit(0);
}

 

转载于:https://www.cnblogs.com/shixuehunk/archive/2011/11/03/2234405.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值