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;
}
相关推荐
EllinY2 小时前
CF2217E Definitely Larger 题解
c++·笔记·算法·构造
玖釉-5 小时前
下一个排列:从字典序到原地算法的完整推导
数据结构·c++·windows·算法
IronMurphy5 小时前
【算法五十】62. 不同路径
算法
影寂ldy6 小时前
C#一维数组
算法
过期动态6 小时前
【LeetCode 热题 100】移动零
java·数据结构·算法·leetcode·职场和发展·rabbitmq
计算机安禾7 小时前
【算法分析与设计】第10篇:下界理论与NP完全性初步
大数据·人工智能·算法
水木流年追梦8 小时前
大模型入门-大模型分布式训练2
开发语言·分布式·python·算法·正则表达式·prompt
sali-tec8 小时前
C# 基于OpenCv的视觉工作流-章78-KRT测量
图像处理·人工智能·数码相机·opencv·算法·计算机视觉
菜菜的顾清寒8 小时前
力扣HOT100(32)二叉树的中序遍历
数据结构·算法·leetcode