zoukankan      html  css  js  c++  java
  • PAT甲级——A1116 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?

     1 #include <iostream>
     2 #include <cmath>
     3 using namespace std;
     4 int rankList[10000] = {0};//存储排名
     5 bool check[10000] = { false };//是否已经查询过
     6 int n, k, id;
     7 bool isPrime(int x)
     8 {
     9     if (x <= 3)
    10         return x > 1;
    11     for (int i = 2; i*i <= x; ++i)
    12         if (x%i == 0)
    13             return false;
    14     return true;
    15 }
    16 int main()
    17 {
    18     cin >> n;
    19     for (int i = 1; i <= n; ++i)
    20     {
    21         cin >> id;
    22         rankList[id] = i;
    23     }
    24     cin >> k;
    25     while (k--)
    26     {
    27         cin >> id;
    28         if (rankList[id] == 0)
    29             printf("%04d: Are you kidding?
    ", id);
    30         else if (check[id] == true)
    31             printf("%04d: Checked
    ", id);
    32         else if (rankList[id] == 1)
    33             printf("%04d: Mystery Award
    ", id);
    34         else if (isPrime(rankList[id]))
    35             printf("%04d: Minion
    ", id);
    36         else
    37             printf("%04d: Chocolate
    ", id);
    38         check[id] = true;
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    终于开通了
    <input>表单元素readonly时光标仍然可见
    关于字体
    SSI架构中get***方法潜在调用
    为uploads文件夹瘦身
    在JSP里使用CKEditor和CKFinder
    centos5.5上搭建svn服务器
    多文件上传
    属性化ATL,DCOM,SIM,IID
    BSTR转换成char*
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11461369.html
Copyright © 2011-2022 走看看