Description
一块N x
N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案。写一个程序来找出将原始
图案按照以下列转换方法转换成新图案的最小方式:
#1:转90度:图案按顺时针转90度。
#2:转180度:图案按顺时针转180度。
#3:转270度:图案按顺时针转270度。
#4:反射:图案在水平方向翻转(形成原图案的镜像)。
#5:组合:图案在水平方向翻转,然后按照#1-#3之一转换。
#6:不改变:原图案不改变。
#7:无效转换:无法用以上方法得到新图案。
如果有多种可用的转换方法,请选择序号最小的那个。
Input
第一行:
单独的一个整数N。
第二行到第N+1行: N行每行N个字符(不是“@”就是“-”);这是转换前的正方形。
第N+2行到第2*N+1行:
N行每行N个字符(不是“@”就是“-”);这是转换后的正方形。
Output
单独的一行包括1到7之间的一个数字(在上文已描述)表明需要将转换前的正方形变为转换后的正方形的转换方法。
Sample Input
3
@-@
---
@@-
@-@
@--
--@
Sample Output
1
解题思路:先读入原来和转换后的图形,储存在两个二维字符数组里面,然后分别写出六种方案的过程,用原来的图形去一一比对,如果符合转换后的图形就输出相应的数字,如果都不行就输出7。
程序:
var
n,i,flag,flag_c:integer;
a,b,c,d:array[0..10,0..10]of char;
procedure init;
var
i,j:integer;
s:array[0..10] of string;
begin
readln(n);
for i:=1 to n do
readln(s[i]);
for i:=1 to n do
for j:=1 to n do
a[i,j]:=s[i][j];
for i:=1 to n do
readln(s[i]);
for i:=1 to n do
for j:=1 to n do
b[i,j]:=s[i][j];
end;
function same:boolean;
var
i,j:integer;
begin
for i:=1 to n do
for j:=1 to n do
if b[i,j]<>c[i,j] then exit(false);
same:=true;
end;
function jiushi:boolean;
var
i,j:integer;
begin
for i:=n downto 1 do
for j:=1 to n do
c[j,i]:=a[n-i+1,j];
if same then exit(true) else exit(false);
end;
function yibaiba:boolean;
var
i,j:integer;
begin
for i:=n downto 1 do
for j:=1 to n do
c[j,i]:=a[n-j+1,n-i+1];
if same then exit(true) else exit(false);
end;
function erbaiqi:boolean;
var
i,j:integer;
begin
for i:=n downto 1 do
for j:=n downto 1 do
c[n-j+1,i]:=a[i,j];
if same then exit(true) else exit(false);
end;
function jingxiang:boolean;
var
i,j:integer;
begin
for i:=1 to n do
for j:=1 to n do
c[j,n-i+1]:=a[j,i];
if same then exit(true) else exit(false);
end;
function zuhe:boolean;
var
i,j:integer;
begin
for i:=1 to n do
for j:=1 to n do
d[i,j]:=a[i,j];
for i:=1 to n do
for j:=1 to n do
a[i,j]:=c[i,j];
if jiushi then exit(true);
if yibaiba then exit(true);
if erbaiqi then exit(true);
zuhe:=false;
end;
procedure main;
begin
if jiushi then begin writeln(1); halt; end
else if yibaiba then begin writeln(2); halt; end
else if erbaiqi then begin writeln(3); halt; end
else if jingxiang then begin writeln(4); halt; end
else if zuhe then begin writeln(5); halt; end
else if same then begin writeln(6); halt; end
else writeln(7);
end;
begin
init;
main;
end.