欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVa340 Master-Mind Hints

程序员文章站 2024-02-24 22:29:46
...
//UVa340 Master-Mind Hints
#include<stdio.h>
#define max 105 
int main(){
	//freopen("date.in","r",stdin);
	int n, a[max], b[max];
	int kase = 0;
	while(scanf("%d",&n) == 1 && n){ //n=0 时结束循环
		printf("Game%d:\n",++kase);
		//答案序列
		for(int i = 0; i < n; i++)
			scanf("%d",&a[i]);
		//猜测序列
		while(1){
			int A = 0, B = 0;
			//获取并计算A
			for(int i = 0; i<n; i++){
				scanf("%d",&b[i]);
				if(a[i]==b[i]) A++;
			}
			//内循环出口条件,游戏切换
			if(b[0] == 0) break;
			//计算A+B的值
			for(int d = 1; d <= 9; d++){
				int c1 = 0, c2 = 0;
				for(int i = 0; i < n; i++){
					if(a[i] == d) c1++;
					if(b[i] == d) c2++;
				}
				if(c1 < c2) B += c1;else B += c2;
			}
			printf("		(%d,%d)\n", A, B-A);
			//continue 下一场游戏,下一个猜测序列
		}
		//新的游戏
	}
	return 0;
}
/*
DATE IN:
4
1 3 5 5
1 1 2 3
4 3 3 5
6 5 5 1
6 1 3 5
1 3 5 5
0 0 0 0
10
1 2 2 2 4 5 6 6 6 9
1 2 3 4 5 6 7 8 9 1
1 1 2 2 3 3 4 4 5 5 
1 2 1 3 1 5 1 6 1 9
1 2 2 5 5 5 6 6 6 7
0 0 0 0 0 0 0 0 0 0 
0
-------------------
DATE OUT:
Game1:
                (1,1)
                (2,0)
                (1,2)
                (1,2)
                (4,0)
Game2:
                (2,4)
                (3,2)
                (5,0)
                (7,0)
*/