UVa340——Master-Mind Hints

本文提供了一段使用C++编写的竞赛代码,并对其进行了详细的解释。该代码涉及数组操作、循环和条件判断等基本编程概念,适用于初学者理解C++编程的基础知识。

题目很简单。

下面的是AC的代码:

#include <iostream>
using namespace std;
const int MAX = 1010;


int main()
{
//	freopen("340.txt", "r", stdin);
	int a[MAX], b[MAX];
	int i, j, n, A, B;
	int count = 1;
	while(cin >> n, n)
	{		
		for(i = 0; i < n; i++)
			cin >> a[i];
		cout << "Game " << count++ << ":" << endl;
		while(true)
		{
			A = B = 0;
			for(i = 0; i < n; i++)
			{
				cin >> b[i];
				if(a[i] == b[i])
					A++;
			}
			if(b[0] == 0)
				break;
			for(i = 0; i < 10; i++)
			{
				int c1 = 0, c2 = 0;
				for(j = 0; j < n; j++)
				{
					if(a[j] == i)
						c1++;
					if(b[j] == i)
						c2++;
				}
				if(c1 < c2)
					B += c1;
				else
					B += c2;
			}
			cout << "    (" << A << ',' << B - A << ')' << endl;
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值