1949.cpp

来自「浙江大学ACM 1949题Error Correction 其实不难」· C++ 代码 · 共 71 行

CPP
71
字号
// 1949.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	ifstream cin("a.txt");
	int a[100][100],i,x,y,n,h,l,hs,ls,hw,lw;
	while(cin>>i)
	{
		ls=0;
		hs=0;
		if(i==0)break;
		for(x=0;x<i;x++)
		{
			for(y=0;y<i;y++)
			{
				cin>>n;
				a[x][y]=n;
			}
		}
		for(x=0;x<i;x++)
		{
			h=0;
			for(y=0;y<i;y++)
			{
				if(a[x][y]==1)
					h++;
			}
			if(h%2==1)
			{
				hs++;
				hw=x+1;
			}
		}
		if(hs>1)
		{
			cout<<"Corrupt"<<endl;
			continue;
		}
		for(x=0;x<i;x++)
		{
			l=0;
			for(y=0;y<i;y++)
			{
				if(a[y][x]==1)
					l++;
			}
			if(l%2==1)
			{
				ls++;
				lw=x+1;
			}
		}
		if(ls>1)
		{
			cout<<"Corrupt"<<endl;
			continue;
		}
		if(ls==1&&hs==1)
			cout<<"Change bit ("<<hw<<","<<lw<<")"<<endl;
		else
			cout<<"OK"<<endl;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?