Description
1 0 1 0 0 0 0 0 1 1 1 1 0 1 0 1
The sums of the rows are 2, 0, 4 and 2. The sums of the columns are 2, 2, 2 and 2.
Your job is to write a program that reads in a matrix and checks if it has the parity property. If not, your program should check if the parity property can be established by changing only one bit. If this is not possible either, the matrix should be classified as corrupt.
Input
Output
Sample Input
4 1 0 1 0 0 0 0 0 1 1 1 1 0 1 0 1 4 1 0 1 0 0 0 1 0 1 1 1 1 0 1 0 1 4 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 1 0
Sample Output
OK Change bit (2,3) Corrupt
较为简单的模拟题
#include <stdio.h>
const int maxn=102;
int a[maxn][maxn];
void solve(int n)
{
int ans=0,bns=0;
int cnt=0,k=0,g=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
cnt+=a[i][j];
a[i][n+1]=(cnt%2);
cnt=0;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
cnt+=a[j][i];
a[n+2][i]=(cnt%2);
cnt=0;
}
for(int i=0;i<n;i++) {
if(a[i][n+1]%2==1) {ans++;k=i;}
if(a[n+2][i]%2==1) {bns++;g=i;}
}
if(ans==0&&bns==0) printf("OK\n");
else if(ans==1&&bns==1) printf("Change bit (%d,%d)\n",k+1,g+1);
else printf("Corrupt\n");
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++) scanf("%d",&a[i][j]);
solve(n);
}
return 0;
}