Poj2260 problem solution (not too watery)

1. As long as one row is not 0 or even, there must be one column and only one column is not 0 or even, otherwise only Corrupt can be output.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int map_[105][105];
int col[105];
int row[105];
int n;
int r,c;
int di,dj;
int main()
{
    
    
    while(scanf("%d",&n)==1&&n)
    {
    
    
        r=0;
        c=0;
        di=0;
        dj=0;
        memset(col,0,sizeof(col));
        memset(row,0,sizeof(row));
        for(int i=0;i<n;i++)
        {
    
    
            for(int j=0;j<n;j++)
            {
    
    
                scanf("%d",&map_[i][j]);
            }
        }
        for(int i=0;i<n;i++)
        {
    
    
            for(int j=0;j<n;j++)
            {
    
    
                col[i]=col[i]+map_[j][i];
                row[i]=row[i]+map_[i][j];
            }
        }
        for(int i=0;i<n;i++)
        {
    
    
            if(col[i]%2!=0)
            {
    
    
                c++;
                dj=i+1;
            }
            if(row[i]&1)
            {
    
    
                r++;
                di=i+1;
            }
        }
        if(r==0&&c==0)
        {
    
    
            printf("OK\n");
        }
        else if(r==c&&r==1)
        {
    
    
            printf("Change bit (%d,%d)\n",di,dj);
        }
        else
        {
    
    
            printf("Corrupt\n");
        }
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/mingjiweixiao/article/details/113434740