Description
A Boolean matrix has the parity property when each row and each column has an even sum, I. e. contains an even number of BITs which are set. here's a 4x4 matrix which has the parity property:
1 0 1 00 0 0 01 1 1 10 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 shocould check if the parity property can be established by changing only one bit. if this is not possible either, the matrix shocould be classified
As upt.
Input
The input will contain in one or more test cases. the first line of each test case contains one integer n (n <100), representing the size of the matrix. on the next n lines, there will be n integers per line. no other integers
0 and 1 will occur in the Matrix. input will be terminated by a value of 0 for N.
Output
For each matrix in the input file, print one line. if the matrix already has the parity property, print "OK ". if the parity property can be established by changing one bit, print "change bit (I, j)" Where I is the row and j
Column of the bit to be changed. Otherwise, print "Upload upt ".
Sample Input
41 0 1 00 0 0 01 1 1 10 1 0 141 0 1 00 0 1 01 1 1 10 1 0 141 0 1 00 1 1 01 1 1 10 1 0 10
Sample output
OKChange bit (2,3)Corrupt
/* It is not hard to understand the meaning of the question, that is, to add each column in each row to an even number, output OK if not, by changing one of the values, we can output and change the coordinates as required. Otherwise, we will output corrupt. My idea is to leave the sum of each row and the sum of each column in the array, if the odd number of an array exceeds 1, it will certainly not work. If it is an even number, it is unnecessary. If every array has an odd number, the locations of the two odd numbers in the output are changed coordinates, such as 1 0 1 00 0 1 01 1 1 10 1 0 1 rows sum array: B: 2 1 4 2 columns sum array: C: 2 2 3 2 so the changed coordinates are (2, 3) */# include <iostream> using namespace STD; int main () {int A [105] [105], B [105], C [105], I, j, N, sum; while (CIN> N, N) {for (I = 0; I <N; I ++) {for (j = 0; j <n; j ++) {Ci N> A [I] [J] ;}} int CNT = 0; for (I = 0; I <n; I ++) {B [I] = 0; for (j = 0; j <n; j ++) {B [I] + = A [I] [J] ;}} for (I = 0; I <n; I ++) {C [I] = 0; For (j = 0; j <n; j ++) {c [I] + = A [J] [I] ;}} int sum1 = 0, sum2 = 0, flag1, flag2; for (I = 0; I <N; I ++) {If (B [I] % 2) {sum1 ++; flag1 = I ;}} for (I = 0; I <n; I ++) {If (C [I] % 2) {sum2 ++; flag2 = I ;}} if (sum1> 1 | sum2> 1) cout <"upt" <Endl; else if (! Sum1 &&! Sum2) cout <"OK" <Endl; else cout <"change bit (" <flag1 + 1 <"," <flag2 + 1 <") "<Endl;} return 0 ;}