1059

作者: 峡迩 | 来源:发表于2017-09-05 10:01 被阅读0次
//超时啦!
//

#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>


using namespace std;

class Stu_info
{
public:
    Stu_info() = delete;
    Stu_info(string &s, unsigned r) :id(s), rank(r) {};
    unsigned get_rank() const { return rank; }
    bool get_checked() const { return checked; }
    string get_id() const { return id; }
    void check() { checked = true; }

private:
    string id;
    unsigned rank = 0;
    bool checked = false;
};

bool prime_number(unsigned u)
{
    bool ret = true;
    if (u == 2)
    {
        return ret;
    }
    for (unsigned i = 2; i < u; ++i)        //循环令u除以比自身小的所有数字(2》u-1),如果能整除,则不是素数。返回false!
    {
        if ((u%i) == 0)
            ret= false;
    }
    return ret;                         //如果通过判断条件,则是素数,返回true!
}

int main()
{
    unsigned n;
    cin >> n;

    vector<Stu_info> data;
    for (unsigned i = 0; i < n; ++i)
    {
        string tmp;
        cin >> tmp;
        data.push_back(Stu_info(tmp, (i + 1))); //(i+1)为常量表达式!
    }

    unsigned k;
    cin >> k;

    for(unsigned i=0;i<k;++i)
    {
        string tmp;
        cin >> tmp;

        bool has_find = false;
        for (auto &r : data)
        {
            if (tmp == r.get_id())
            {
                has_find = true;
                auto rank = r.get_rank();
                if (r.get_checked())
                {
                    cout <<r.get_id()<< ": Checked";
                }
                else
                {
                    if (rank == 1)
                    {
                        cout<<r.get_id()<<": Mystery Award";
                    }
                    else
                    {
                        if(prime_number(rank))
                            cout<< r.get_id() << ": Minion"; 
                        else
                            cout << r.get_id() << ": Chocolate";
                    }
                    r.check();
                }
            }
        }
        if (!has_find)          //循环结束后,如果找到了has_find为true!
        {
            cout << tmp<<": Are you kidding?";
        }
        if (i != (k - 1))
        {
            cout << endl;
        }
    }
    
    system("pause");
    return 0;
}

//同样超时!各种容器的效率问题?
//

#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>


using namespace std;

class Stu_info
{
public:
    Stu_info() = delete;
    Stu_info(string &s, unsigned r) :id(s), rank(r) {};
    
    bool get_checked() const { return checked; }
    string get_id() const { return id; }
    string get_award();

private:
    string id;
    unsigned rank = 0;
    bool checked = false;
    bool prime_number(unsigned u) ;
};

string Stu_info::get_award()
{
    string tmp;

    if (!checked)
    {
        checked = true;
        if (rank == 1)
            tmp = "Mystery Award";
        else
        {
            if (prime_number(rank))
                tmp = "Minion";
            else
                tmp = "Chocolate";
        }
    }
    else
        tmp = "Checked";

    return tmp;
}

bool Stu_info::prime_number(unsigned u)
{
    bool ret = true;
    if (u == 2)
    {
        return ret;
    }
    for (unsigned i = 2; i < u; ++i)        //循环令u除以比自身小的所有数字(2》u-1),如果能整除,则不是素数。返回false!
    {
        if ((u%i) == 0)
            ret = false;
    }
    return ret;                         //如果通过判断条件,则是素数,返回true!
}


int main()
{
    unsigned n;
    cin >> n;

    vector<Stu_info> data;
    for (unsigned i = 0; i < n; ++i)
    {
        string tmp;
        cin >> tmp;
        data.push_back(Stu_info(tmp, (i + 1))); //(i+1)为常量表达式!
    }

    unsigned k;
    cin >> k;

    for(unsigned i=0;i<k;++i)
    {
        string tmp;
        cin >> tmp;

        bool has_find = false;
        for (auto &r : data)
        {
            if (tmp == r.get_id())
            {
                has_find = true;
                cout << tmp << ": " << r.get_award();   
            }
        }
        if (!has_find)          //循环结束后,如果找到了has_find为true!
        {
            cout << tmp<<": Are you kidding?";
        }
        if (i != (k - 1))
        {
            cout << endl;
        }
    }
    
    system("pause");
    return 0;
}

相关文章

  • 1059

  • 1059

    老耿和老田闹玩笑,小王帮老田治服了老耿。老耿斗不过王、田联手,只好好言求饶。老田大沾了便宜,眉开眼笑,喜不自...

  • 1059

    8月19日,农历七月二十二,周五 高温39度,现在室外35度,还是很热。 早上带上我的专用坐垫,开车接娃爸下班。上...

  • 亲子(1059)

    2020.2.24 星期一 小雨 二月二龙抬头!今天的小雨莫非是龙王爷要用贵如油的春雨,赶走今年的疫情? ...

  • 日记1059

    2022年11月12日,星期六 雨 今天是周六,但今天儿子还要上课,让儿子开心的是,今天比平常上课晚一小时,所以我...

  • 【日精进打卡第353天】

    扬州方圆~~周亮 【知~学习】学习一级建造师内容 《六项精进》3遍。累积1059遍 《大学》3遍。累积1059遍 ...

  • 情绪要稳定

    无戒学堂IP营打卡第1天,1059字,累计 1059字。 对一个中年女人来说,情绪稳定的重要性不言而喻。 就比...

  • 1059 Prime Factors (25 分)

    1059 Prime Factors (25 分) Given any positive integer N, y...

  • 2019-05-21 P1059

    题目链接:https://www.luogu.org/problemnew/show/P1059

  • EMF-20210828 三句话过好人生

    2021-0828,打卡第1059天。Indulging your desire is the biggest e...

网友评论

      本文标题:1059

      本文链接:https://www.haomeiwen.com/subject/yqcujxtx.html