此题就是纯模拟,根据题目中叙述的几种转换学出相应转换,进行比较就可以了,没什么需要特别注意的。
/*
ID: acmerfi1
PROG: transform
LANG: C++
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 10
typedef struct board
{
int n;
char a[MAX][MAX];
}Board;
Board rotate(Board b) // 顺时针旋转90度
{
Board temp = b;
for(int i = 0; i < b.n; i++)
{
for(int j = 0; j < b.n; j++)
{
temp.a[j][b.n-1-i] = b.a[i][j];
}
}
return temp;
}
Board reflect(Board b) // 立体以中间为轴进行旋转
{
Board temp = b;
for(int i = 0; i < b.n; i++)
{
for(int j = 0; j < b.n; j++)
{
temp.a[i][b.n-1-j] = b.a[i][j];
}
}
return temp;
}
int equale(Board a, Board b) // 判断两个图形是否相同的函数 如果相同返回1,不相同返回0
{
if(a.n != b.n) return 0;
for(int i = 0; i < a.n; i++)
{
for(int j = 0; j < b.n; j++)
{
if(a.a[i][j] != b.a[i][j]) return 0;
}
}
return 1;
}
Board getdata(int n) //读取数据
{
Board b;
b.n = n;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
scanf("%c", &b.a[i][j]);
}
getchar();
}
return b;
}
int main()
{
freopen("transform.in", "r", stdin);
freopen("transform.out", "w", stdout);
int n, change;
Board b, nb;
scanf("%d%*c", &n);
b = getdata(n);
nb = getdata(n);
if(equale(nb, rotate(b)))
change = 1;
else if(equale(nb, rotate(rotate(b))))
change = 2;
else if(equale(nb, rotate(rotate(rotate(b)))))
change = 3;
else if(equale(nb, reflect(b)))
change = 4;
else if(equale(nb, rotate(reflect(b)))
|| equale(nb, rotate(rotate(reflect(b))))
|| equale(nb, rotate(rotate(rotate(reflect(b))))))
change = 5;
else if(equale(nb, b))
change = 6;
else
change = 7;
printf("%d\n", change);
return 0;
}