zoukankan      html  css  js  c++  java
  • 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

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

  • 相关阅读:
    每日日报
    每日日报
    flink入门到实战(2)flink优化总结
    flink入门到实战(1)入门学习
    机器学习算法一般步骤
    hadoop入门到实战(1)hive优化总结
    划重点|iOS15正式发布, 全新的通知推送系统,你必须要知道!
    云知声 Atlas 超算平台: 基于 Fluid + Alluxio 的计算加速实践
    终端卡顿优化的全记录
    云湖共生释放企业数据价值
  • 原文地址:https://www.cnblogs.com/kamisamalz/p/13586939.html
Copyright © 2011-2022 走看看