POJ2260 ZOJ1949 Error Correction

//4_4_1:	Error Correction 布尔矩阵奇偶均势特性的保持POJ2260 ZOJ1949
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
	int n,i,j,k,row_cnt,col_cnt;
	int row[100],col[100],matrix[100][100];
	while(cin >> n,n != 0)
	{
		row_cnt = 0;
		col_cnt = 0;
		memset(row,0,sizeof(row));
		memset(col,0,sizeof(col));
		for(i = 0;i < n;i ++)
			for(j = 0;j < n; j++)
			{
				cin >> matrix[i][j];
				row[i] += matrix[i][j];
				col[j] += matrix[i][j];
			}
		for(k = 0;k < n;k ++)
		{
			if(row[k] % 2 == 1)	{row_cnt++,i = k;} 
			if(col[k] % 2 == 1)	{col_cnt++,j = k;}
		}
		if(row_cnt == 0 && col_cnt == 0)		
			printf("OK\n");
		else if(row_cnt == 1 && col_cnt == 1)	
			printf("Change bit (%d,%d)\n",i + 1,j + 1);
		else
			printf("Corrupt\n");
	}
	return 0;
}
/*测试结果:通过POJ2260 ZOJ1949检测
4
1 0 1 0
0 0 0 0
1 1 1 1
0 1 0 1
OK
4
1 0 1 0
0 0 1 0
1 1 1 1
0 1 0 1
Change bit (2,3)
4
1 0 1 0
0 1 1 0
1 1 1 1
0 1 0 1
Corrupt
0
请按任意键继续. . .
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值