zoukankan      html  css  js  c++  java
  • PAT(Advanced Level)A1116. Come on! Let's C

    题意

    举行了比赛,冠军有神秘奖,名次是素数的人会收到小黄人,其他的任何人会收到巧克力,不在名单里的人也要检查出来,还要识别出已经检查过的人

    思路

    • 分别用2个unordered_map<int, int>来记住排名和是否有在名单里
    • 接下来依次判断即可

    代码

    #include <iostream>
    #include <vector>
    #include <queue>
    #include <map>
    #include <string.h>
    #include <set>
    #include <unordered_map>
    #include <algorithm>
    using namespace std;
    unordered_map<int, int> ranklist;
    unordered_map<int, int> namelist;
    bool is_prime(int x) {
        if(x <= 1)  return false;
        for(int i = 2; i * i <= x; i++) {
            if(x % i == 0)   return false;
        }
        return true;
    }
    int main() {
        int N, K, tmp;
        cin >> N;
        for(int i = 1; i <= N; i++) {
            cin >> tmp;
            ranklist[tmp] = i;
            namelist[tmp] = 1;
        }
        cin >> K;
        bool checked[10001] = {0};
        for(int i = 0; i < K; i++) {
            cin >> tmp;
            if(namelist[tmp] == 0)                          // 不在名单上
                printf("%04d: Are you kidding?
    ", tmp);
            else if(checked[tmp])                           // 已经检查过了
                printf("%04d: Checked
    ", tmp);
            else {
                checked[tmp] = true;
                if(ranklist[tmp] == 1)                      // 第一名
                    printf("%04d: Mystery Award
    ", tmp);
                else if(is_prime(ranklist[tmp]))            // 名次为素数
                    printf("%04d: Minion
    ", tmp);
                else
                    printf("%04d: Chocolate
    ", tmp);       // 巧克力
            }
        }
        return 0;
    }
    
    如有转载,请注明出处QAQ
  • 相关阅读:
    激活程序进程并显示最前
    ClickOnce 部署 API 以编程方式检查应用程序更新
    管理员权限运行
    扩展支持全选的CheckBox列。
    转 winfrom组件圆角
    转 无边框四周阴影
    转 实现类似QQ的窗体停靠
    关闭ShowDialog的模态窗口
    TextBox 显示横线
    转 无损转换Image为Icon
  • 原文地址:https://www.cnblogs.com/MartinLwx/p/14532843.html
Copyright © 2011-2022 走看看