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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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)
成功发现列坐标变成了行坐标。那么行坐标呢?它是怎么变化的呢?
以789为例它们原来在不同的列现在都是第1列看来后期的
列与行有关当然也得与n有关所以猜测试为n-i,结果呢3-3=0,不对啊,
再加个1试试就是n-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;
}