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;
}
相关推荐
叼烟扛炮7 小时前
C++ 知识点18 内部类
开发语言·c++·算法·内部类
YOGOD有神7 小时前
用AI自动从谷歌地图抓取海外客户,我跑了一次7小时的任务,结果出乎意料
算法
汉克老师7 小时前
GESP5级C++考试语法知识(十五、分治算法(二))
c++·算法·排序算法·分治算法·gesp5级·gesp五级
快瞳科技7 小时前
小样本学习在珍稀鸟类识别中的突破:仅需5张图,让AI认识濒危物种
算法
汉克老师8 小时前
GESP6级C++考试语法知识(五、格雷码)
c++·算法·位运算·异或·gesp6级·gesp六级·格雷码
Ulyanov8 小时前
《从质点到位姿:基于Python与PyVista的导弹制导控制全栈仿真》: 可视化革命——基于 PyVista 的 3D 战场构建与实时渲染
开发语言·python·算法·3d·系统仿真
,,?!,8 小时前
数据结构算法-排序算法
数据结构·算法·排序算法
小白编程锤炼8 小时前
深入解析:质量门禁
人工智能·算法·架构·vibe-coding
yongui478349 小时前
基于 GA 优化的 BP 神经网络算法分析与 MATLAB 实现
神经网络·算法·matlab
阿旭超级学得完10 小时前
C++11(初始化)
java·开发语言·数据结构·c++·算法