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;
}
相关推荐
前端小白在前进38 分钟前
力扣刷题:复原IP地址
tcp/ip·算法·leetcode
yaoh.wang1 小时前
力扣(LeetCode) 94: 二叉树的中序遍历 - 解法思路
python·算法·leetcode·面试·职场和发展·二叉树·跳槽
Evand J1 小时前
【课题推荐】基于视觉(像素坐标)与 IMU 的目标/自身运动估计(Visual-Inertial Odometry, VIO),课题介绍与算法示例
人工智能·算法·计算机视觉
xu_yule1 小时前
算法基础(背包问题)—分组背包和混合背包
c++·算法·动态规划·分组背包·混合背包
蓝色汪洋1 小时前
数码串和oj
数据结构·算法
努力学算法的蒟蒻1 小时前
day39(12.20)——leetcode面试经典150
算法·leetcode·面试
科学最TOP1 小时前
xLSTM-Mixer:基于记忆混合的多变量时间序列预测
大数据·人工智能·算法·机器学习·时间序列
xlq223222 小时前
29.哈希(下)
算法·哈希算法·散列表
阿昭L2 小时前
leetcode链表是否有环
算法·leetcode·链表
yaoh.wang2 小时前
力扣(LeetCode) 83: 删除排序链表中的重复元素 - 解法思路
程序人生·算法·leetcode·链表·面试·职场和发展