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;
}
相关推荐
NAGNIP5 小时前
轻松搞懂全连接神经网络结构!
人工智能·算法·面试
NAGNIP6 小时前
一文搞懂激活函数!
算法·面试
董董灿是个攻城狮6 小时前
AI 视觉连载7:传统 CV 之高斯滤波实战
算法
爱理财的程序媛12 小时前
openclaw 盯盘实践
算法
MobotStone15 小时前
Google发布Nano Banana 2:更快更便宜,图片生成能力全面升级
算法
颜酱19 小时前
队列练习系列:从基础到进阶的完整实现
javascript·后端·算法
用户57573033462419 小时前
两数之和:从 JSON 对象到 Map,大厂面试官到底在考察什么?
算法
程序猿追19 小时前
“马”上行动:手把手教你基于灵珠平台打造春节“全能数字管家”
算法
ZPC82101 天前
docker 镜像备份
人工智能·算法·fpga开发·机器人