UVa340 Master-Mind Hints

来源:互联网 发布:数据库pdforacle网盘 编辑:程序博客网 时间:2024/04/18 12:33
//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;//获取并计算Afor(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:41 3 5 51 1 2 34 3 3 56 5 5 16 1 3 51 3 5 50 0 0 0101 2 2 2 4 5 6 6 6 91 2 3 4 5 6 7 8 9 11 1 2 2 3 3 4 4 5 5 1 2 1 3 1 5 1 6 1 91 2 2 5 5 5 6 6 6 70 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)*/

0 0