UVA-340 Master-Mind Hints

UVA-340 Master-Mind Hints

题目大意:designer 说出一组数字, breaker 也说出一组数字(不包括 0 ,所以 0 可以当成标记),如果designer 与 breaker 的位置和数字均相等,则 strong++ ,反之则 weak++。 且参与比较过的数字不再参与后面的比较。

Sample Input

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

Sample Output

Game 1:
(1,1)
(2,0)
(1,2)
(1,2)
(4,0)
Game 2:
(2,4)
(3,2)
(5,0)
(7,0)

解题思路:先比较 strong , 比较后要标记一下,再比较 weak 。

//UVA-340 Master-Mind Hints
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define m 5007
int T = 1;
int designer[m] = { 0 };
int breaker[m] = { 1 };
int design[m] ={ 0 };
int main () {
    int M;
    while(scanf("%d",&M) && M != 0) {
        for(int i = 0; i < M; i++) {
           scanf("%d",&design[i]);
        }
        printf ("Game %d:\n",T++);
        for (int j = 0; j < M; j++) {
            scanf ("%d",&breaker[j]);
        }
        while (breaker[0] != 0) {
            int strong = 0, weak = 0;
            memcpy(designer,design,m);
            for (int i = 0; i < M;i++) {
                if (designer[i] == breaker[i]) {
                    strong++;
                    breaker[i] = designer[i] = 0;   //此处两个都是i
                }
            }
            for (int i = 0; i < M; i++) {
                if (designer[i] == 0)
                    continue;
                for (int j = 0; j < M; j++) {
                    if (designer[i] == breaker[j]) {
                        weak++;
                        designer[i] = breaker[j] = 0;  //此处两个分别为 i 和 j.
                        break;
                    }
                }
            }
            printf ("    (%d,%d)\n",strong,weak);
            for (int j = 0; j < M; j++) {
                scanf ("%d",&breaker[j]);
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值