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;
}
相关推荐
一个不知名程序员www2 小时前
算法学习入门 --- 哈希表和unordered_map、unordered_set(C++)
c++·算法
Sarvartha3 小时前
C++ STL 栈的便捷使用
c++·算法
夏鹏今天学习了吗3 小时前
【LeetCode热题100(92/100)】多数元素
算法·leetcode·职场和发展
飞Link4 小时前
深度解析 MSER 最大稳定极值区域算法
人工智能·opencv·算法·计算机视觉
bubiyoushang8884 小时前
基于CLEAN算法的杂波抑制Matlab仿真实现
数据结构·算法·matlab
2401_894828125 小时前
从原理到实战:随机森林算法全解析(附 Python 完整代码)
开发语言·python·算法·随机森林
Remember_9935 小时前
【LeetCode精选算法】前缀和专题二
算法·哈希算法·散列表
源代码•宸5 小时前
Leetcode—509. 斐波那契数【简单】
经验分享·算法·leetcode·面试·golang·记忆化搜索·动规
博大世界6 小时前
matlab结构体数组定义
数据结构·算法
Loo国昌6 小时前
【LangChain1.0】第九阶段:文档处理工程 (LlamaIndex)
人工智能·后端·python·算法·langchain