zoukankan      html  css  js  c++  java
  • PAT 1116 Come on! Let's C [简单]

    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 (104​​), 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?

     题目大意:给出n个排名的id,序号代表排名,如果是第一名输出Mystery Award,素数名输出Minion,其他人输出Chocolate,重复查询提示。

    水水的AC:

    #include <iostream>
    #include <algorithm>
    #include<cstdio>
    #include <map>
    #include<cmath>
    using namespace std;
    
    map<int,string> award;
    map<int,int> query;
    bool prime(int a){
        int q=sqrt(a);
        for(int i=2;i<=q;i++){
            if(a%i==0){
                return false;
            }
        }
        return true;
    }
    int main()
    {
        int n,no;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&no);
            if(i==0){
                award[no]="Mystery Award";
            }else{
                if(prime(i+1)){
                    award[no]="Minion";
                }else{
                    award[no]="Chocolate";
                }
            }
        }
        int m;
        scanf("%d",&m);
        for(int i=0;i<m;i++){
            scanf("%d",&no);
            if(award.count(no)==0){
                printf("%04d: Are you kidding?
    ",no);
            }else {
                if(query.count(no)==1){
                    printf("%04d: Checked
    ",no);
                }else{//使用printf怎么输出String啊啊?好像没办法。。。
                    printf("%04d: ",no);
                    cout<<award[no]<<"
    ";
                    query[no]=1;
                }
            }
        }
        return 0;
    }

    //有一个槽点,就是在写最后出现了个问题,代码中有注释,所以就混合使用printf和cout输出了,罪过。

    1.查了一下发现是需要将其转换成char*类型,直接使用:

    printf("%04d: %s
    ",no,award[no].c_str());

    即可!c_str()就是将string转换为char*的函数!!!

  • 相关阅读:
    AOP
    session的一些原理
    HttpContext.Cache和Application的区别
    什么是COM组件
    MS—SQL数据库索引的应用
    会话状态(转)
    LINQ体验(6)——LINQ语句之Join和Order By(转)
    永远不停止学习,才是程序员最大的财富,欢迎加入CMS研究室
    面向对象
    从瀑布型开发到迭代型开发的转变
  • 原文地址:https://www.cnblogs.com/BlueBlueSea/p/9915671.html
Copyright © 2011-2022 走看看