1.2.2 Transformations
A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:
- #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
- #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
- #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
- #4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
- #5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
- #6: No Change: The original pattern was not changed.
- #7: Invalid Transformation: The new pattern was not obtained by any of the above methods.
In the case that more than one transform could have been used, choose the one with the minimum number above.
PROGRAM NAME: transform
INPUT FORMAT
Line 1: | A single integer, N |
Line 2..N+1: | N lines of N characters (each either `@' or `-'); this is the square before transformation |
Line N+2..2*N+1: | N lines of N characters (each either `@' or `-'); this is the square after transformation |
SAMPLE INPUT (file transform.in)
3 @-@ --- @@- @-@ @-- --@
OUTPUT FORMAT
A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.
SAMPLE OUTPUT (file transform.out)
1
{ ID: makeeca1 PROG: transform LANG: PASCAL } program transform; type arr=array[1..10,1..10]of boolean; var a,b:arr; ch:char; i,j,n:longint; procedure p1; var t:arr; begin fillchar(t,sizeof(t),0); for i:=1 to n do for j:=1 to n do t[j,n-i+1]:=a[i,j]; a:=t; end; procedure p2; var t:arr; begin fillchar(t,sizeof(t),0); for i:=1 to n do for j:=1 to n do t[i,j]:=a[i,n-j+1]; a:=t; end; function ok:boolean; var i,j:longint; begin for i:=1 to n do for j:=1 to n do if a[i,j]<>b[i,j]then exit(false); exit(true); end; begin assign(input,'transform.in');reset(input); assign(output,'transform.out');rewrite(output); readln(n); fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); for i:=1 to n do begin for j:=1 to n do begin read(ch);if ch='@' then a[i,j]:=true;end; readln; end; for i:=1 to n do begin for j:=1 to n do begin read(ch);if ch='@' then b[i,j]:=true;end; readln; end; p1;if ok then begin writeln(1);close(output);halt;end; p1;if ok then begin writeln(2);close(output);halt;end; p1;if ok then begin writeln(3);close(output);halt;end; p1;p2;if ok then begin writeln(4);close(output);halt;end; p1;if ok then begin writeln(5);close(output);halt;end; p1;if ok then begin writeln(5);close(output);halt;end; p1;if ok then begin writeln(5);close(output);halt;end; p1;p2;if ok then begin writeln(6);close(output);halt;end; writeln(7);close(output); end.