关闭

zoj 1949 Error Correction

182人阅读 评论(0) 收藏 举报
#include "iostream"
#include "memory.h"
using namespace std;

int matrix[110][110], rowsum[110], columnsum[110], rowans[110], columnans[110];

int main()
{
	int n, i, j, rowcount, columncount;
	while (cin >> n && n)
	{
		memset(rowsum, 0, sizeof(rowsum));
		memset(columnsum, 0, sizeof(columnsum));
		memset(rowans, 0, sizeof(rowans));
		memset(columnans, 0, sizeof(columnans));
		rowcount = columncount = 0;
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				cin >> matrix[i][j];
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
			{
				rowsum[i] += matrix[i][j];
				columnsum[i] += matrix[j][i];
			}
		for (i = 0; i < n; i++)
		{
			if (rowsum[i] % 2 != 0)
				rowans[i] = 1;
			if (columnsum[i] % 2 != 0)
				columnans[i] = 1;
		}
		for (i = 0; i < n; i++)
		{
			if (rowans[i] == 1)
				rowcount++;
			if (columnans[i] == 1)
				columncount++;
		}
		if (rowcount == 0 && columncount == 0)
			cout << "OK" << endl;
		else if (rowcount == 1 && columncount == 1)
		{
			int temp1, temp2;
			for (i = 0; i < n; i++)
				if (rowans[i] == 1)
			        temp1 = i;
			for (i = 0; i < n; i++)
				if (columnans[i] == 1)
					temp2 = i;
					 cout << "Change bit (" << temp1+ 1<< ","<< temp2 + 1 << ")" << endl;
		}
		else
			cout << "Corrupt" << endl;
	}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:487956次
    • 积分:8068
    • 等级:
    • 排名:第2514名
    • 原创:414篇
    • 转载:22篇
    • 译文:0篇
    • 评论:55条
    最新评论