A square pattern of size N x N (1 <= N <= 10) black and whitesquare tiles is transformed into another square pattern. Write a programthat will recognize the minimum transformation that has been applied tothe 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 (turnedinto a mirror image of itself by reflecting around a vertical line in themiddle of the image).
- #5: Combination: The pattern was reflected horizontally and thensubjected 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 beforetransformation |
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 (describedabove) that categorizes the transformation required to change from the`before' representation to the `after' representation.SAMPLE OUTPUT (file transform.out)
1
CODE:
/*
ID:sotifis3
LANG:C++
TASK:transform
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
const int inf=0xfffffff;
typedef long long ll;
using namespace std;
char a[15][15], c[15][15];
char b[15][15];
int n;
void show()
{
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
printf("%c ", a[i][j]);
}
printf("\n");
}
}
bool judge()
{
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
if(c[i][j] != b[i][j]) return false;
}
}
return true;
}
void work1()
{
int ii = -1, jj = 0;
for(int j = 0; j < n; ++j){
ii++;
for(int i = n - 1; i >= 0; --i){
c[ii][jj++] = a[i][j];
}
jj = 0;
}
}
void work2()
{
int ii = -1, jj = 0;
for(int i = n - 1; i >= 0; --i){
ii++;
for(int j = n - 1; j >=0; --j){
c[ii][jj++] = a[i][j];
}
jj = 0;
}
}
void work3()
{
int ii = -1, jj = 0;
for(int j = n - 1; j >= 0; --j){
ii++;
for(int i = 0; i < n; ++i){
c[ii][jj++] = a[i][j];
}
jj = 0;
}
}
void work4()
{
int ii = 0, jj = n;
for(int j = 0; j <= n/2; ++j){
jj--;
for(int i = 0; i < n; ++i){
c[ii++][jj] = a[i][j];
}
ii = 0;
}
jj = -1, ii = 0;
for(int j = n - 1; j > n/2; --j){
jj++;
for(int i = 0; i < n; ++i){
c[ii++][jj] = a[i][j];
}
ii = 0;
}
}
bool work5()
{
work4();
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
a[i][j] = c[i][j];
}
}
}
bool work6()
{
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
if(a[i][j] != b[i][j]) return false;
}
}
return true;
}
int main()
{
//freopen("in", "r", stdin);
freopen("transform.in","r",stdin);
freopen("transform.out","w",stdout);
while(~scanf("%d", &n)){
for(int i = 0; i < n; ++i){
scanf("%s", a[i]);
}
for(int i = 0; i < n; ++i){
scanf("%s", b[i]);
}
work1();
if(judge()){
printf("1\n");
continue;
}
work2();
if(judge()){
printf("2\n");
continue;
}
work3();
if(judge()){
printf("3\n");
continue;
}
work4();
if(judge()){
printf("4\n");
continue;
}
work6();
if(judge()){
printf("6\n");
continue;
}
work5();
int t = 3, ok = 0;
while(t--){
work1();
if(judge()){
ok = 1;
break;
}
work2();
if(judge()){
ok = 1;
break;
}
work3();
if(judge()){
ok = 1;
break;
}
}
if(ok == 1){
printf("5\n");
continue;
}
printf("7\n");
}
return 0;
}