pascal问题转换图形
解决时间 2021-05-03 01:15
- 提问者网友:贪了杯
- 2021-05-02 11:19
一块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:
(file transform.in)
第一行: 单独的一个整数N。
第二行到第N+1行: N行每行N个字符(不是“@”就是“-”);这是转换前的正方形。
第N+2行到第2*N+1行: N行每行N个字符(不是“@”就是“-”);这是转换后的正方形。
OUTPUT FORMAT:
(file transform.out)
单独的一行包括1到7之间的一个数字(在上文已描述)表明需要将转换前的正方形变为转换后的正方形的转换方法。
[编辑] SAMPLE INPUT
3
@—@
———
@@—
@—@
@——
——@
[编辑] SAMPLE OUTPUT
1
来自"
http://www.nocow.cn/index.php/Translate:USACO/transform"
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-05-02 11:30
可以考虑模拟每一个情况的结果与需要的结果进行对比(从1开始到最后),只要有一种可能了就可以输出该序号了。
全部回答
- 1楼网友:拜訪者
- 2021-05-02 11:45
var
c1,c2,c3,c4,c5:array[1..11] of string;
n,ii:longint;
x1:boolean;
procedure rr;
var
i:longint;
begin
readln(n);
for i:=1 to n do readln(c1[i]);
for i:=1 to n do readln(c2[i]);
end;
procedure one;
var i,j:longint; x:boolean;
begin
x:=true;
for i:=1 to n do c4[i]:='';
for i:=1 to n do for j:=1 to n do c4[j]:=c4[j]+c3[n-i+1][j];
for i:=1 to n do if c2[i]<>c4[i] then x:=false;
if x1 then if x then begin writeln('1'); halt; end;
end;
procedure two;
var i,j:longint; x:boolean;
begin
x:=true;
for i:=1 to n do c4[i]:='';
for i:=1 to n do for j:=1 to n do c4[j]:=c4[j]+c3[n-i+1][j];
for i:=1 to n do if c2[i]<>c4[i] then x:=false;
if x1 then if x then begin writeln('2'); halt; end;
end;
procedure three;
var i,j:longint; x:boolean;
begin
x:=true;
for i:=1 to n do c4[i]:='';
for i:=1 to n do for j:=1 to n do c4[j]:=c4[j]+c3[n-i+1][j];
for i:=1 to n do if c2[i]<>c4[i] then x:=false;
if x1 then if x then begin writeln('3'); halt; end;
end;
procedure four;
var i,j:longint; x:boolean;
begin
x:=true;
for i:=1 to n do c4[i]:='';
for i:=1 to n do for j:=n downto 1 do c4[i]:=c4[i]+c1[i][j];
for i:=1 to n do if c2[i]<>c4[i] then x:=false;
for i:=1 to n do c5[i]:=c4[i];
if x1 then if x then begin writeln('4'); halt; end;
end;
procedure five;
var
i:longint; x:boolean;
begin
x1:=false;
x:=true;
four;
for i:=1 to n do c3[i]:=c5[i];
one;
for i:=1 to n do if c2[i]<>c4[i] then x:=false;
if x then begin writeln('5'); halt; end;
for i:=1 to n do c3[i]:=c4[i];
two;
x:=true;
for i:=1 to n do if c2[i]<>c4[i] then x:=false;
if x then begin writeln('5'); halt; end;
for i:=1 to n do c3[i]:=c4[i];
three;
for i:=1 to n do if c2[i]<>c4[i] then x:=false;
if x then begin writeln('5'); halt; end;
end;
procedure six;
var i:longint; x:boolean;
begin
x:=true;
for i:=1 to n do if c1[i]<>c2[i] then x:=false;
if x then begin writeln('6'); halt; end;
end;
begin
assign(input,'transform.in');
reset(input);
assign(output,'transform.out');
rewrite(output);
x1:=true;
rr;
for ii:=1 to n do c3[ii]:=c1[ii];
one;
x1:=true;
for ii:=1 to n do c3[ii]:=c4[ii];
two;
x1:=true;
three;
x1:=true;
four;
x1:=true;
five;
x1:=true;
six;
writeln('7');
close(input);
close(output);
end.
我要举报
大家都在看
推荐资讯