代码如下
#include<bits/stdc++.h>
using namespace std;
char ch1[20][20],ch2[20][20],ch[20][20];
int n;
int judge()
{
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(ch[i][j]!=ch2[i][j])return 0;
}
}
return 1;
}
void print()
{
cout<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
printf("%c",ch1[i][j]);
}
printf("\n");
}
cout<<endl;
}
int func1()
{
//print();
for(int i=1,v=n;i<=n;i++,v--){
for(int j=1,u=1;j<=n;j++,u++){
ch[u][v]=ch1[i][j];
}
}
//print();
return judge();
}
int func2()
{
//print();
//print() ;
for(int i=1,v=n;i<=n;i++,v--){
for(int j=1,u=n;j<=n;j++,u--){
ch[v][u]=ch1[i][j];
}
}
//print();
return judge();
}
int func3()
{
for(int i=1,v=1;i<=n;++i,++v)
for(int j=1,u=n;j<=n;++j,--u)
ch[u][v]=ch1[i][j];
return judge();
}
int func4()
{
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
ch[i][j]=ch1[i][n+1-j];
}
}
return judge();
}
int func5()
{
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
ch[i][j]=ch1[i][n+1-j];
}
}
if(!func1())func3();
if(!func2())func2();
if(!func3())return 0;
return 1;
}
int func6()
{
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
ch[i][j]=ch1[i][j];
}
}
return judge();
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%s",ch1[i]+1);
for(int i=1;i<=n;i++)scanf("%s",ch2[i]+1);
if(func1()){
printf("1");
return 0;
}
if(func2()){
printf("2");
return 0;
}
if(func3()){
printf("3");
return 0;
}
if(func4()){
printf("4");
return 0;
}
if(func5()){
printf("5");
return 0;
}
if(func6()){
printf("6");
return 0;
}
printf("7");
return 0;
}