如果有某一行與某一列不吻合,
則要換的那個位元就是(那行,那列)。
如果有多行多列,或是行有問題但是列沒問題,或者反過來,
則都沒辦法判斷要換那個位元。
如果都吻合,那就OK,沒什麼問題。
[C](0.016)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main() | |
{ | |
int n; | |
while( scanf( "%d", &n ) != EOF && n != 0 ) | |
{ | |
int matrix[105][105] = {0}; | |
int i, j; | |
int row = -1, col = -1, check; | |
int fail = 0; | |
for( i = 0 ; i < n ; i++ ) | |
{ | |
check = 0; | |
for( j = 0 ; j < n ; j++ ) | |
{ | |
scanf( "%d", &matrix[i][j] ); | |
check ^= matrix[i][j]; | |
} | |
if( check ) | |
{ | |
if( row == -1 ) | |
row = i; | |
else | |
fail = 1; | |
} | |
} | |
if( !fail ) | |
{ | |
for( i = 0 ; i < n ; i++ ) | |
{ | |
check = 0; | |
for( j = 0 ; j < n ; j++ ) | |
check ^= matrix[j][i]; | |
if( check ) | |
{ | |
if( col == -1 ) | |
col = i; | |
else | |
fail = 1; | |
} | |
} | |
} | |
if( fail ) | |
printf( "Corrupt\n" ); | |
else | |
{ | |
if( row == -1 && col == -1 ) | |
printf( "OK\n" ); | |
else if( (row == -1 && col != -1) || (row != -1 && col == -1) ) | |
printf( "Corrupt\n" ); | |
else | |
printf( "Change bit (%d,%d)\n", row+1, col+1 ); | |
} | |
} | |
return 0; | |
} |
0 意見:
張貼留言