UVa 541 - Error Correction

#include<stdio.h>
int main()
{
    int mat[120][120];
    int i,j,n,p,q,c1,c2,sum1,sum2;
    while(scanf("%d",&n)==1 && n!=0)
    {
        p=0,q=0,c1=0,c2=0;
        for(i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
                scanf("%d",&mat[i][j]);
        }
        for(i=0; i<n; i++)
        {
            sum1=0;
            for(j=0; j<n; j++)
            {
                sum1+=mat[i][j];
            }
            if(sum1%2!=0)
            {
                p=i+1;
                c1++;
            }
        }
        for(i=0; i<n; i++)
        {
            sum2=0;
            for(j=0; j<n; j++)
            {
                sum2+=mat[j][i];
            }
            if(sum2%2!=0)
            {
                q=i+1;
                c2++;
            }
        }
        if(c1==0 && c2==0)
            printf("OK\n");
        else if(c1==1 && c2==1)
            printf("Change bit (%d,%d)\n",p,q);
        else
            printf("Corrupt\n");
    }
    return 0;
}
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 মন্তব্য(গুলি):

একটি মন্তব্য পোস্ট করুন