UVa340 Master-Mind Hints
【摘要】
//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...
-
//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)
-
*/
文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。
原文链接:gwj1314.blog.csdn.net/article/details/54846331
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)