zoukankan      html  css  js  c++  java
  • 1116 Come on! Let's C (20 分)(hash散列)

    "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:

    1. The Champion will receive a "Mystery Award" (such as a BIG collection of students' research papers...).
    2. Those who ranked as a prime number will receive the best award -- the Minions (小黄人)!
    3. 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?

    生词

    英文 解释
    College 学院
    department
    Champion 冠军
    Mystery 神秘事物
    Minions 小黄人
    ranklist 用户排名
    contestant 比赛者
    query 查询

    分析:

    ran数组标记每个id对应的排名,集合ss存储所有已经询问过的id,如果发现当前id已经出现在ss中,则输出“Checked”,如果ran[id] == 0说明当前id不在排名列表中,所以输出“Are you kidding?”,如果ran[id]为1则输出“Minion”,如果ran[id]为素数则输出“Mystery Award”,否则输出“Chocolate”

    原文链接:https://blog.csdn.net/liuchuo/article/details/52505009

    题解

    自己用哈希做的,感觉也比较简单,对于不同的情况标记不同的值即可。

    #include <bits/stdc++.h>
    
    using namespace std;
    bool prime(int n)
    {
        if(n<=1) return false;
        for(int i=2;i*i<=n;i++){
            if(n%i==0) return false;
        }
        return true;
    }
    int rk[10010];
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("1.txt", "r", stdin);
    #endif
        int n,k,data;
        cin>>n;
        for(int i=0; i<n; i++)
        {
            cin>>data;
            rk[data]=i+1;
        }
        cin>>k;
        for(int i=0; i<k; i++)
        {
            cin>>data;
            if(rk[data]==1){
                printf("%04d",data);
                cout<<": Mystery Award"<<endl;
                rk[data]=-1;
            }else if(prime(rk[data])){
                printf("%04d",data);
                cout<<": Minion"<<endl;
                rk[data]=-1;
            }else if(rk[data]==-1){
                printf("%04d",data);
                cout<<": Checked"<<endl;
            }else if(rk[data]==0){
                printf("%04d",data);
                cout<<": Are you kidding?"<<endl;
            }else{
                printf("%04d",data);
                cout<<": Chocolate"<<endl;
                rk[data]=-1;
            }
        }
        return 0;
    }
    

    本文来自博客园,作者:勇往直前的力量,转载请注明原文链接:https://www.cnblogs.com/moonlight1999/p/15776092.html

  • 相关阅读:
    【原创】【js】screenLeft screenTop screenX screenY属性的有效性和兼容性研究
    兼容兼容兼容:浏览器兼容性大集合
    Vue 打包成APP后首屏出现白屏问题
    uniapp 安卓app端本地打包错误: Not found -1,6 at view.umd.min.js:1
    uniapp 下获取cid
    uniapp fill abort statuscode:-1
    Vuex刷新时数据会消失,那如何解决?为什么还要使用Vuex
    vue 安装失败;vue不是内部或外部命令
    js 文件下载,多个文件下载,pdf下载
    uni-App 去掉顶部导航栏
  • 原文地址:https://www.cnblogs.com/moonlight1999/p/15776092.html
Copyright © 2011-2022 走看看