(数组应用四:数值矩阵的运算4.4.1)POJ 2260 Error Correction(奇偶均匀特性)

/*
 * POJ_2260.cpp
 *
 *  Created on: 2013年10月25日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>

using namespace std;

const int maxn = 110;
int a[maxn][maxn], row[maxn], col[maxn];

int main() {
	int n;
	while (scanf("%d", &n) != EOF, n) {
		int i ,j, k;
		//首先将所有的行和、列和初始化为0
		for (i = 0; i < n; ++i) {
			row[i] = 0;
			col[i] = 0;
		}

		//初始化数值矩阵
		for (i = 0; i < n; ++i) {
			for (j = 0; j < n; ++j) {
				scanf("%d", &a[i][j]);
			}
		}

		//求行和、列和
		for (i = 0; i < n; ++i) {
			for (j = 0; j < n; ++j) {
				row[i] += a[i][j];
				col[j] += a[i][j];
			}
		}

		int cr = 0, cc = 0;
		for (k = 0; k < n; ++k) {
			if (row[k] % 2 == 1) {
				cr++;
				i = k;
			}

			if (col[k] % 2 == 1) {
				cc++;
				j = k;
			}
		}

		if(cc == 0 && cr ==0){
			printf("OK\n");
		}else if( cc == 1 && cr == 1){
			printf("Change bit (%d,%d)\n",i+1,j+1);
		}else{
			printf("Corrupt\n");
		}
	}

	return 0;
}

你可能感兴趣的:((数组应用四:数值矩阵的运算4.4.1)POJ 2260 Error Correction(奇偶均匀特性))