C++交叉奇偶校验

#include <iostream>
using namespace std;

int main()
{
int a[100][100];
int n,x[100],y[100],tempx=-1,flagx=0,tempy=-1,flagy=0;
cin>>n;
for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
         cin>>a[i][j];
         if(a[i][j]==1)
            x[i]++;
        }
       if(x[i]%2!=0)
       {
       tempx=i;
       flagx++;
       }

    }
for(int j=0;j<n;j++)
    {
        for(int i=0;i<n;i++)
        {

         if(a[i][j]==1)
            y[j]++;
        }
       if(y[j]%2!=0)
       {
       tempy=j;
       flagy++;
       }

    }
    if(tempx==-1 &&tempy==-1)
        cout<<"OK"<<endl;
    else if(flagx==1 && flagy==1)
        cout<<"Error In ("<<tempx+1<<","<<tempy+1<<")"<<endl;
    else
        cout<<"Error"<<endl;

return 0;


}
 

猜你喜欢

转载自blog.csdn.net/weixin_40076972/article/details/84699620