[题目描述]
Transformations
方块转换
一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案。写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式:
#1:转90度:图案按顺时针转90度。
#2:转180度:图案按顺时针转180度。
#3:转270度:图案按顺时针转270度。
#4:反射:图案在水平方向翻转(形成原图案的镜像)。
#5:组合:图案在水平方向翻转,然后按照#1-#3之一转换。
#6:不改变:原图案不改变。
#7:无效转换:无法用以上方法得到新图案。
如果有多种可用的转换方法,请选择序号最小的那个。
PROGRAM NAME: transform
INPUT FORMAT
第一行: | 单独的一个整数N。 |
第二行到第N+1行: | N行每行N个字符(不是“@”就是“-”);这是转换前的正方形。 |
第N+2行到第2*N+1行: | N行每行N个字符(不是“@”就是“-”);这是转换后的正方形。 |
SAMPLE INPUT (file transform.in)
3
@-@
---
@@-
@-@
@--
--@
OUTPUT FORMAT
单独的一行包括1到7之间的一个数字(在上文已描述)表明需要将转换前的正方形变为转换后的正方形的
转换方法。
SAMPLE OUTPUT (file transform.out)
1
[解题思路]
枚举1~7的方案,模拟比较即可。
注意一定要顺序枚举方案,因为多种方案时,取序号最小的。
[Code]
{
ID: zane2951
PROG: transform
LANG: PASCAL
}
program transform;
type
matrix=array[0..11,0..11] of char;
var
f,g,k:matrix;
i,j,n:longint;
//----------check----------
function check(x,y:matrix):boolean;
var
i,j:longint;
begin
for i:=1 to n do
for j:=1 to n do
if x[i,j]<>y[i,j] then exit(false);
exit(true);
end;
//---------change----------
function change(x:matrix):matrix;
var
i,j,ce:longint;
p:matrix;
begin
for i:=1 to n do
begin
ce:=n-i+1;
for j:=1 to n do p[j,ce]:=x[i,j];
end;
exit(p);
end;
//---------reflex----------
function reflex(x:matrix):matrix;
var
i,j:longint;
p:matrix;
tmp:char;
begin
p:=x;
for i:=1 to n do
for j:=1 to n>>1 do
begin
tmp:=p[i,j]; p[i,j]:=p[i,n-j+1]; p[i,n-j+1]:=tmp;
end;
exit(p);
end;
//----------main-----------
begin
assign(input,'transform.in'); reset(input);
assign(output,'transform.out'); rewrite(output);
readln(n);
for i:=1 to n do
begin
for j:=1 to n do read(f[i,j]);
readln;
end;
for i:=1 to n do
begin
for j:=1 to n do read(g[i,j]);
readln;
end;
k:=change(f);
if check(k,g) then begin writeln(1); halt; end;
k:=change(k);
if check(k,g) then begin writeln(2); halt; end;
k:=change(k);
if check(k,g) then begin writeln(3); halt; end;
k:=reflex(f);
if check(k,g) then begin writeln(4); halt; end;
k:=change(k);
if check(k,g) then begin writeln(5); halt; end;
k:=change(k);
if check(k,g) then begin writeln(5); halt; end;
k:=change(k);
if check(k,g) then begin writeln(5); halt; end;
if check(f,g) then begin writeln(6); halt; end;
writeln(7);
close(input); close(output);
end.