You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
5.7 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 15;
char a[N][N];//原始图案
char c[N][N];//目标图案
char t[N][N];//转换后的图案
char t2[N][N];
int n;
//判断两个二维数组是不是一致
bool equal() {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (t[i][j] != c[i][j]) return false;
return true;
}
int main() {
cin >> n;
//读入原始图案
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
cin >> a[i][j];
//读入目标图案
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
cin >> c[i][j];
//1、顺时针转90度
//通过实际例子找规律得i,j--->j,n-i+1
/**
1 2 3 7 4 1
4 5 6 --> 8 5 2
7 8 9 9 6 3
1(1,1),(1,3)
2(1,2),(2,3)
3(1,3),(3,3)
??
7891
nn-i,3-3=0,
1n-i+1,
*/
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[j][n - i + 1] = a[i][j];
//如果通过输出1返回
if (equal()) {
cout << 1 << endl;
return 0;
}
//2、顺时针转180度
/**
1 2 3 9 8 7
4 5 6 --> 6 5 4
7 8 9 3 2 1
1,1--->n,n
1,2--->n,n-1
1,3--->n,n-2
2,1--->n-1,n
2,2--->n-1,n-1
i,j---> n-i+1,n-j+1
*/
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[n - i + 1][n - j + 1] = a[i][j];
//如果通过输出2返回
if (equal()) {
cout << 2 << endl;
return 0;
}
//3、顺时针转270度
//通过实际例子找规律得i,j---> n-j+1,i
/**
1 2 3 3 6 9
4 5 6 --> 2 5 8
7 8 9 1 4 7
1,1--->n,1
1,2--->n-1,1
1,3--->n-2,1
2,1--->n,2
2,2--->n-1,2
i,j---> n-j+1,i
*/
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[n - j + 1][i] = a[i][j];
//如果通过输出3返回
if (equal()) {
cout << 3 << endl;
return 0;
}
//4、图案在水平方向翻转
//通过实际例子,
/**
1 2 3 3 2 1
4 5 6 --> 6 5 4
7 8 9 9 8 7
1,1--->1,n
1,2--->1,n-1
1,3--->1,n-2
2,1--->2,n
2,2--->2,n-1
i,j---> i,n-j+1
*/
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[i][n - j + 1] = a[i][j];
//如果通过输出4返回
if (equal()) {
cout << 4 << endl;
return 0;
}
//5、组合 图案在水平方向翻转,然后再按照 1 3 之间的一种再次转换。
//***********************************************************************************************
//5.1 水平+顺时针90度
//水平
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[i][n - j + 1] = a[i][j];
//复制出来
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t2[i][j] = t[i][j];
//顺时针90度
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[j][n - i + 1] = t2[i][j];
//如果通过输出5返回
if (equal()) {
cout << 5 << endl;
return 0;
}
//***********************************************************************************************
//***********************************************************************************************
//5.2 水平+180度
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[i][n - j + 1] = a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t2[i][j] = t[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[n - i + 1][n - j + 1] = t2[i][j];
//如果通过输出5返回
if (equal()) {
cout << 5 << endl;
return 0;
}
//***********************************************************************************************
//***********************************************************************************************
//5.3 水平+270度
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[i][n - j + 1] = a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t2[i][j] = t[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[n - j + 1][i] = t2[i][j];
//如果通过输出5返回
if (equal()) {
cout << 5 << endl;
return 0;
}
//***********************************************************************************************
//6、不改变
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
t[i][j] = a[i][j];
//如果通过输出6返回
if (equal()) {
cout << 6 << endl;
return 0;
}
//7、无效转换
cout << 7 << endl;
return 0;
}