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 }
  • 相关阅读:
    Swift技术之如何在iOS 8下使用Swift设计一个自定义的输入法 (主要是NSLayoutConstraint 的使用)
    android 旋转手机的时候,如何忽略onCreate再次被系统调用?
    在iOS 8中使用UIAlertController
    09_android入门_采用android-async-http开源项目的GET方式或POST方式实现登陆案例
    一些工具的版本问题 valgrind gdb 以及编译
    C struct __attribute__ ((__packed__))
    C++ class 只允许堆创建/只允许栈创建
    Shell 字符串操作
    存储系统的分类
    ssh 到服务器然后输入中文保存到本地变成乱码
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11461369.html
Copyright © 2011-2022 走看看