• PAT 甲级 1116 Come on! Let's C (20分)


    "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?

    【AC steps】:1、[ 确定第一 ]    2、[ 判断素数 ]   3、[ 分类输出 ]

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 bool isPrime(int x)
     5 {
     6     if(x < 2) return false;
     7     for(int i = 2; i*i <= x; i++)
     8         if(x%i==0) return false;
     9     return true;
    10 }
    11 
    12 int main()
    13 {
    14     map<string, int> m, mm;
    15     int n; cin >> n;
    16     for(int i = 1; i <= n; i++)
    17     {
    18         string s; cin >> s;
    19         m[s] = i;
    20     }
    21     cin >> n;
    22     for(int i = 1; i <= n; i++)
    23     {
    24         string s; cin >> s;
    25         if(m[s])
    26         {
    27             if(!mm[s])
    28             {
    29                 mm[s] = 1;
    30                 if(m[s] == 1) cout << s << ": Mystery Award" << endl;
    31                 else if(isPrime(m[s])) cout << s << ": Minion" << endl;
    32                 else cout << s << ": Chocolate" << endl;
    33             }
    34             else cout << s << ": Checked" << endl;
    35         }
    36         else cout << s << ": Are you kidding?" << endl;
    37     }
    38     return 0;
    39 }
    View Code

    "看不懂的代码的皆可通过手动在纸上推导理解思路,一定不要懒!!!"

  • 相关阅读:
    2021.3.16
    2021.3.15
    通过指定的URL获取返回图片的BASE64编码
    Redis系统学习之缓存穿透,缓存击穿,缓存雪崩的概念及其解决方案
    Redis系统学习之其他高可用模型
    Redis系统学习之哨兵模式
    Redis系统学习之主从复制
    Redis系统学习之发布订阅
    Redis系统学习之持久化(AOF)
    Redis系统学习之持久化(RDB)
  • 原文地址:https://www.cnblogs.com/kamisamalz/p/13586939.html
Copyright © 2020-2023  润新知