I have some pictures, some of them are same. And the colors are only black and white.So I want to make a chanllenge to you. You need to distinguish whether two pictures are same or not.Note that each picture can be rotated.Get more information from the sample.Input
A number n(
1≤n≤10
1≤n≤10) indicate the number of cases.Then for each case, two matrix stands for the pictures. Each picture is a 5 X 5 matrix only contains 0(black) or 1(white).Output
Output 'Yes' if the two picture are same or 'No' otherwise.Sample Input
2
11111
00000
00000
00000
00000
10000
10000
10000
10000
10000
10000
10000
10000
10000
10000
00010
00001
00001
00001
00001
Sample Output
YesNo
思路:将两个数组进行对比,若相等则输出Yes;若不相等,则将数组b顺时针旋转90度,在进行比对;重复步骤二3次,3次后没有比对成功则输出“No”
#include <iostream> #include <string> #include<cstdlib> using namespace std; int a[5][5]; int b[5][5]; void display(int c[5][5]) { int i,j; for(i=0;i<5;i++)//输入数组c for(j=0;j<5;j++) { if(j==4) cout<<c[i][j]<<endl; else cout<<c[i][j]<<" "; } } int is_equal()//判断数组是否相等 { int i,j; int flag=0; for(i=0;i<5;i++) { for(j=0;j<5;j++) { if(a[i][j]!=b[i][j]) { flag=1; break; } } if(flag==1) break; } if(flag==0) return 1; } void revenge()//将数组b顺时针转动 { int i,j,t; int m=2; for(i=0;i<=2;i++) { for(j=i;j<5-1-i;j++) { t=b[i][j]; b[i][j]=b[5-1-j][i]; b[5-1-j][i]=b[5-1-i][5-1-j]; b[5-1-i][5-1-j]=b[j][5-1-i]; b[j][5-1-i]=t; } } } int main() { int n,i,j; cin>>n; while(n--) { for(i=0;i<5;i++)//输入数组a for(j=0;j<5;j++) { cin>>a[i][j]; } for(i=0;i<5;i++)//输入数组b for(j=0;j<5;j++) { cin>>b[i][j]; } if(is_equal()==1)//若数组a,b匹配成功 { cout<<"Yes"<<endl; continue; } //第一次顺时针旋转 revenge(); if(is_equal()==1)//若数组a,b匹配成功 { cout<<"Yes"<<endl; continue; } //第二次顺时针旋转 revenge(); if(is_equal()==1)//若数组a,b匹配成功 { cout<<"Yes"<<endl; continue; } //第三次顺时针旋转 revenge(); if(is_equal()==1)//若数组a,b匹配成功 { cout<<"Yes"<<endl; continue; } cout<<"No"<<endl; } return 0; }