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

    1116. Come on! Let's C (20)

    时间限制
    200 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    "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 (<=10000), 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?

    思路

    简单的逻辑题,记录下选手排名和是否已经给过奖品就行。注意没在排行榜上的id多次查询后还是输出"Are you kidding?"而不是"Checked"。

    代码
    #include<iostream>
    #include<cstdio>
    #include<map>
    #include<math.h>
    #include<vector>
    using namespace std;
    
    bool isPrime(const int num)
    {
       if(num == 2)
         return true;
       if(num % 2 == 0)
        return false;
       for(int i = 2;i < num;i++)
       {
           if(num % i == 0)
             return false;
       }
       return true;
    }
    
    int main()
    {
      int N;
      while(cin >> N)
      {
         map<int,bool> dic;
         vector<int> rankList(10010);
         for(int i = 1;i <= N;i++)
         {
             int number;
             cin >> number;
             dic.insert(pair<int,bool>(number,false));
             rankList[number] = i ;
         }
         int K;
         cin >> K;
         for(int i = 0;i <K;i++)
         {
             int query;
             cin >> query;
             printf("%04d",query);
             if(dic.count(query) <= 0)
             {
                 cout << ": Are you kidding?" << endl;
                 continue;
             }
             if(dic[query])
             {
                 cout << ": Checked" << endl;
                 continue;
             }
    
             if(rankList[query] == 1)
             {
                 dic[query] = true;
                 cout << ": Mystery Award" << endl;
             }
             else if(isPrime(rankList[query]))
             {
                 dic[query] = true;
                 cout << ": Minion" << endl;
             }
             else
             {
                 dic[query] = true;
                 cout << ": Chocolate" << endl;
             }
         }
      }
    }
    
    
    
     
  • 相关阅读:
    Gogs http和ssh地址显示localhost的问题
    SQL Server从读写频繁的大表中删除大批量数据
    Java Spring Boot: Unable to determine jdbc url from datasource
    NPOI导入Excel日期格式的处理
    手把手教你整合最优雅SSM框架
    JDBC链接数据库MySQL 8.0 Public Key Retrieval is not allowed 错误的解决方法
    Vim 入门教程
    jquery.i18n.properties前端国际化方案
    生产者消费者模式中条件判断是使用while而不是if
    ThreadPoolExecutor 中的 shutdown() 、 shutdownNow() 、 awaitTermination() 的用法和区别
  • 原文地址:https://www.cnblogs.com/0kk470/p/7635332.html
Copyright © 2011-2022 走看看