3*3的字符串旋转三下,只得到90分,不知道代码为什么会出现RA
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 205;
char mat[MAXN][MAXN];
char subMat[4][5][5];
int dir[9][2] = {{-1, 1}, {0, 1}, {1, 1}, {1, 0},
{1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {0, 0}};
int n, m;
void getAllPos()
{
//rotate
for(int k = 1; k < 4; k ++)
for(int i = 0; i < 3; i ++)
for(int j = 0; j < 3; j ++)
subMat[k][i][j] = subMat[k-1][2-j][i];
}
void solve()
{
for(int i = 1; i < n-1; i ++)
for(int j = 1; j < m-1; j ++) {
for(int t = 0; t < 4; t ++) {
bool flag = false;
// 9 positions, judge one by one
for(int k = 0; k < 9; k ++){
int tx = i + dir[k][0];
int ty = j + dir[k][1];
int px = 1 + dir[k][0];
int py = 1 + dir[k][1];
if(mat[tx][ty] != subMat[t][px][py]) {
flag = true;
break;
}
}
if(!flag) {
cout << i+1 << " " << j+1 << endl;
continue;
}
}
}
}
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i ++)
cin >> mat[i];
for(int i = 0; i < 3; i ++)
cin >> subMat[0][i];
getAllPos();
solve();
return 0;
}