1059

//超时啦!
//

#include "stdafx.h"
#include
#include
#include


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 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> 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 <
//同样超时!各种容器的效率问题?
//

#include "stdafx.h"
#include
#include
#include


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 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> 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)