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;
}
相关推荐
网络工程小王8 分钟前
【大模型(LLM)的业务开发】学习笔记
人工智能·算法·机器学习
y = xⁿ9 分钟前
【Leet Code 】滑动窗口
java·算法·leetcode
WBluuue12 分钟前
数据结构与算法:二项式定理和二项式反演
c++·算法
nianniannnn12 分钟前
力扣104.二叉树的最大深度 110. 平衡二叉树
算法·leetcode·深度优先
_深海凉_22 分钟前
LeetCode热题100-只出现一次的数字
算法·leetcode·职场和发展
nianniannnn41 分钟前
力扣206.反转链表 92.反转链表II
算法·leetcode·链表
澈2071 小时前
哈希表实战:从原理到手写实现
算法·哈希算法
旖-旎1 小时前
哈希表(存在重复元素||)(4)
数据结构·c++·算法·leetcode·哈希算法·散列表
Run_Teenage1 小时前
Linux:认识信号,理解信号的产生和处理
linux·运维·算法
無限進步D1 小时前
蓝桥杯赛前刷题
c++·算法·蓝桥杯·竞赛