1 #include <iostream> 2 #include <cmath> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <string> 7 using namespace std; 8 char a[20][20],b[20][20],c[20][20],d[20][20]; 9 int n; 10 int rotation() //90度依次旋转 11 { 12 for(int j=n;j>=1;j--) 13 { 14 for(int k=1;k<=n;k++) 15 b[k][j]=a[n-j+1][k]; 16 } 17 for(int j=1;j<=n;j++) 18 for(int k=1;k<=n;k++) 19 a[j][k]=b[j][k]; 20 } 21 bool check() // 判断a与d是否相等 22 { 23 for(int i=1;i<=n;i++) 24 for(int j=1;j<=n;j++) 25 if(a[i][j]!=d[i][j]) return 0; //不相等 ,返回0,表示错误; 26 return 1; //相等返回1,表示正确; 27 } 28 int main() 29 { 30 //freopen("1085.in","r",stdin); 31 //freopen("1085.out","w",stdout); 32 cin>>n; 33 for(int i=1;i<=n;i++) 34 for(int j=1;j<=n;j++) 35 cin>>c[i][j]; 36 for(int i=1;i<=n;i++) 37 for(int j=1;j<=n;j++) 38 cin>>d[i][j]; 39 40 41 for(int i=1;i<=n;i++) 42 for(int j=1;j<=n;j++) 43 a[i][j]=c[i][j]; 44 rotation(); if (check()) {cout<<1<<endl; return 0;} //旋转一次后判断; 90度 45 rotation(); if (check()) {cout<<2<<endl; return 0;} //旋转二次后判断; 180度 46 rotation(); if (check()) {cout<<3<<endl; return 0;} //旋转三次后判断; 270度 47 /* 48 判断数组a与d,上面已经将c数组原始值赋值给a,即判断数组c与d是否相等; 49 */ 50 51 //以下是映射判断; 52 for(int i=1;i<=n;i++) 53 for(int j=1;j<=n;j++) 54 a[i][n-j+1]=c[i][j]; 55 if (check()) {cout<<4<<endl; return 0;} 56 //以下是组合判断; 57 rotation(); if (check()) {cout<<5<<endl; return 0;} 58 rotation(); if (check()) {cout<<5<<endl; return 0;} 59 rotation(); if (check()) {cout<<5<<endl; return 0;} 60 //判断是否相等; 61 for(int i=1;i<=n;i++) 62 for(int j=1;j<=n;j++) 63 a[i][j]=c[i][j]; 64 if (check()) {cout<<6<<endl; return 0;} 65 //直接输出7,上面只要一个正确那么就返回0,表示已经结束了; 66 cout<<"7"<<endl; 67 //fclose(stdin); fclose(stdout); 68 return 0; 69 } 70 /* 71 坑爹的题,太麻烦了; 72 */