340 - Master-Mind Hints (UVA)

题目链接如下:

Online Judge

我的代码如下:

cpp 复制代码
#include <cstdio>
#include <algorithm>
const int maxN = 1000;

int s[maxN], g[maxN], cntS[10], cntG[10];
int N, game, match, tot;

int main(){
    game = 0;
    while(scanf("%d", &N) && N){
        std::fill(cntS, cntS + 10, 0);
        for(int i = 0; i < N; ++i){
            scanf("%d", &s[i]);
            cntS[s[i]]++;
        }
        printf("Game %d:\n", ++game);
        while(1){
            std::fill(cntG, cntG + 10, 0);
            match = 0;
            for(int i = 0; i < N; ++i){
                scanf("%d", &g[i]);
                match += s[i] == g[i] ? 1 : 0;
                cntG[g[i]]++;
            }
            if(!g[0]){
                break;
            }
            tot = 0;
            for(int i = 1; i < 10; ++i){
                tot += std::min(cntS[i], cntG[i]);
            }
            printf("    (%d,%d)\n", match, tot - match);
        }
    }
    return 0;
}
相关推荐
plus4s4 小时前
2月12日(70-72题)
算法
m0_672703315 小时前
上机练习第24天
算法
edisao5 小时前
序幕-内部审计备忘录
java·jvm·算法
shehuiyuelaiyuehao5 小时前
22Java对象的比较
java·python·算法
Dev7z6 小时前
滚压表面强化过程中变形诱导位错演化与梯度晶粒细化机理的数值模拟研究
人工智能·python·算法
吴秋霖6 小时前
apple游客下单逆向分析
python·算法·逆向分析
YunchengLi8 小时前
【计算机图形学中的四元数】2/2 Quaternions for Computer Graphics
人工智能·算法·机器学习
CUC-MenG9 小时前
Codeforces Round 1079 (Div. 2)A,B,C,D,E1,E2,F个人题解
c语言·开发语言·数学·算法
666HZ6669 小时前
数据结构4.0 串
c语言·数据结构·算法
weixin_421585019 小时前
常微分方程
算法