Transformations
按顺序执行各布操作并判断即可,其中旋转部分代码可复用。
代码如下:
/*
ID: xhzdcyy1
PROB: transform
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include<map>
#define cin fin
#define cout fout
using namespace std;
int a[10][10];
int b[10][10];
int c[10][10];
int n;
void fun1(){
int d[10][10];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
d[j][n-i-1]=c[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
c[i][j]=d[i][j];
}
}
return;
}
bool check1(){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(c[i][j]!=b[i][j]) return false;
}
}
return true;
}
int main()
{
ofstream fout ("transform.out");
ifstream fin ("transform.in");
char tmp;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>tmp;
if(tmp=='@') a[i][j]=0;
else a[i][j]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>tmp;
if(tmp=='@') b[i][j]=0;
else b[i][j]=1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
c[i][j]=a[i][j];
}
}
fun1();
if(check1()){
cout<<"1"<<endl;
goto end;
};
fun1();
if(check1()){
cout<<"2"<<endl;
goto end;
};
fun1();
if(check1()){
cout<<"3"<<endl;
goto end;
};
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
c[i][n-j-1]=a[i][j];
}
}
if(check1()){
cout<<"4"<<endl;
goto end;
};
fun1();
if(check1()){
cout<<"5"<<endl;
goto end;
};
fun1();
if(check1()){
cout<<"5"<<endl;
goto end;
};
fun1();
if(check1()){
cout<<"5"<<endl;
goto end;
};
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
c[i][j]=a[i][j];
}
}
if(check1()){
cout<<"6"<<endl;
goto end;
};
cout<<"7"<<endl;
end: return 0;
}