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;
}
相关推荐
Frostnova丶3 小时前
【算法笔记】数学知识
笔记·算法
吴可可1234 小时前
AutoCAD 2016与2014二次开发关键差异
算法
雨白5 小时前
哈希:以时间换空间的算法实战
算法
San813_LDD7 小时前
[数据结构]LeetCode学习
数据结构·算法·图论
x138702859577 小时前
c语言排雷游戏(基础版9*9)
c语言·算法·游戏
sheeta19988 小时前
LeetCode 每日一题笔记 日期:2026.06.06 题目:2196. 根据描述创建二叉树
笔记·算法·leetcode
小欣加油8 小时前
leetcode994 腐烂的橘子
数据结构·c++·算法·leetcode·bfs
QuZero9 小时前
Guava Cache Deep Dive
java·后端·算法·guava
随意起个昵称9 小时前
线性dp-LIS题目4(A Twisty Movement)
算法·动态规划