zoukankan      html  css  js  c++  java
  • 1116 Come on! Let's C

    "Let's C" is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny as the following:

    • 0、 The Champion will receive a "Mystery Award" (such as a BIG collection of students' research papers...).
    • 1、 Those who ranked as a prime number will receive the best award -- the Minions (小黄人)!
    • 2、 Everyone else will receive chocolates.

    Given the final ranklist and a sequence of contestant ID's, you are supposed to tell the corresponding awards.

    Input Specification:

    Each input file contains one test case. For each case, the first line gives a positive integer N (≤), the total number of contestants. Then N lines of the ranklist follow, each in order gives a contestant's ID (a 4-digit number). After the ranklist, there is a positive integer K followed by K query ID's.

    Output Specification:

    For each query, print in a line ID: award where the award is Mystery Award, or Minion, or Chocolate. If the ID is not in the ranklist, print Are you kidding? instead. If the ID has been checked before, print ID: Checked.

    Sample Input:

    6
    1111
    6666
    8888
    1234
    5555
    0001
    6
    8888
    0001
    1111
    2222
    8888
    2222
    
     

    Sample Output:

    8888: Minion
    0001: Chocolate
    1111: Mystery Award
    2222: Are you kidding?
    8888: Checked
    2222: Are you kidding?

    思路:

      按照每种不同的情况输出就行了。

    Code:

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 bool isPrime(int n) {
     6     for (int i = 2; i * i <= n; ++i) {
     7         if (n % i == 0) return false;
     8     }
     9     return true;
    10 }
    11 
    12 int main() {
    13     int n, k;
    14     cin >> n;
    15     string id;
    16     map<string, int> list;
    17     for (int i = 1; i <= n; ++i) {
    18         cin >> id;
    19         list.insert({id, i});
    20     }
    21     cin >> k;
    22     set<string> visited;
    23     for (int i = 0; i < k; ++i) {
    24         cin >> id;
    25         if (list.find(id) == list.end()) {
    26             cout << id << ": Are you kidding?" << endl;
    27         } else if (visited.find(id) != visited.end()) {
    28             cout << id << ": Checked" << endl;
    29         } else if (list[id] == 1) {
    30             cout << id << ": Mystery Award" << endl;
    31         } else if (isPrime(list[id])) {
    32             cout << id << ": Minion" << endl;
    33         } else {
    34             cout << id << ": Chocolate" << endl;
    35         }
    36         visited.insert(id);
    37     }
    38 
    39     return 0;
    40 }
    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    webpack 5 之持久化缓存
    前端资源加载失败优化
    如何用 JS 实现二叉堆
    简单解析一下扫码登陆原理,简单到你想不到!
    实战:Express 模拟 CSRF 攻击
    Yarn 的 Plug&#39;n&#39;Play 特性
    为什么现在我更推荐 pnpm 而不是 npm/yarn?
    小米3移动版刷安卓6.0-小米手机3 移动版 Flyme 6.7.11.24R beta
    小米5手机最后一版安卓6.0 MIUI8 6.11.10 小米5s手机最后一版安卓6.0 MIUI8 7.6.8
    vim格式转换
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12770656.html
Copyright © 2011-2022 走看看