TJU ACM Problem【4157】

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( 1n10 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

Yes

No

思路:将两个数组进行对比,若相等则输出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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值