题解 | 旋转矩阵
#include <bits/stdc++.h>
using namespace std;
const int MAX=100;
int a[MAX][MAX], b[MAX][MAX], c[MAX][MAX], n;
bool cmp() {
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;
}
//将a旋转90度并存储到a中
void rotate() {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
c[i][j] = a[n - 1 - j][i];
memcpy(a, c, sizeof(a));
}
int main() {
while (cin >> n) {
for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)cin >> a[i][j];
for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)cin >> b[i][j];
int res = -1;
for (int i = 0; i < 4; i++) {
if (cmp()) {
res = i;
break;
}
rotate();
}
if (res == -1)cout << -1 << endl;
else cout << res * 90 << endl;
}
}
仍然是学习的上次的旋转矩阵的思路,旋转公式这里只提供了一次旋转,然后进行等值判定

