程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> URAL

URAL

編輯:關於C++
Hamming Code Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

Let us consider four disks intersecting as in the figure. Each of the three shapes formed by the intersection of three disks will be called apetal. Write zero or one on each of the disks. Then write on each petal the remainder in the division by two of the sum of integers on the disks that contain this petal. For example, if there were the integers 0, 1, 0, and 1 written on the disks, then the integers written on the petals will be 0, 1, and 0 (the disks and petals are given in the order shown in the figure). This scheme is called a Hamming code. It has an interesting property: if you enemy changes secretely any of the seven integers, you can determine uniquely which integer has been changed. Solve this problem and you will know how this can be done. Problem illustration

Input

The only line contains seven integers separated with a space, each of them being zero or one. The first four integers are those written on the disks in the order shown in the figure. The following three integers are those written on the petals in the order shown in the figure

Output

Output one line containing seven integers separated with a space. The integers must form a Hamming code. The set of integers may differ from the input set by one integer at most. It is guaranteed that either the input set is a Hamming code or a Hamming code can be obtained from it by changing exactly one integer.

Sample Input

input output
0 1 0 1 1 0 1
0 1 0 0 1 0 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1

直接枚舉

 

#include
using namespace std;
int a[10];
bool ok(int a1, int a2, int a3, int a4, int b1,int b2, int b3)
{
	if ((a1 + a2 + a4) % 2 != b3) return false;
	if ((a1 + a3 + a4) % 2 != b2) return false;
	if ((a2 + a3 + a4) % 2 != b1) return false;
	return true;
}
int main()
{
	while (cin>>a[0])
	{
		for (int i = 1; i < 7; i++)
			cin >> a[i];
		if (ok(a[0], a[1], a[2], a[3], a[4], a[5], a[6]))
		{
			for (int i = 0; i < 7; i++)
			{
				if (i) cout << " ";
				cout << a[i];
			}
			cout << endl;
			continue;
		}
		for (int i = 0; i < 7; i++)
		{
			a[i] = 1^a[i];
			if (ok(a[0], a[1], a[2], a[3], a[4], a[5], a[6]))
			{
				for (int i = 0; i < 7; i++)
				{
					if (i) cout << " ";
					cout << a[i];
				}
				cout << endl;
				break;
			}
			a[i] = 1^a[i];
		}	
	}
}


 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved