其他分享
首页 > 其他分享> > 1062 Talent and Virtue (25 分)

1062 Talent and Virtue (25 分)

作者:互联网

水题~。

struct Node
{
    string id;
    int virtue,talent;
    int total;
    bool operator<(const Node &W) const
    {
        if(total == W.total)
        {
            if(virtue == W.virtue)
                return id<W.id;
            else return virtue > W.virtue;
        }
        else return total > W.total;
    }
}a[N];
int n,lowest,highest;

bool check(int a,int b)
{
    return a>=lowest && b>=lowest;
}

int main()
{
    cin>>n>>lowest>>highest;

    vector<Node> sage,nobleman,foolman,other;

    for(int i=0;i<n;i++)
    {
        cin>>a[i].id>>a[i].virtue>>a[i].talent;
        a[i].total=a[i].virtue+a[i].talent;
    }

    sort(a,a+n);

    for(int i=0;i<n;i++)
    {
        if(check(a[i].virtue,a[i].talent))
        {
            if(a[i].virtue >= highest && a[i].talent >= highest)
                sage.pb(a[i]);
            else if(a[i].virtue >= highest)
                nobleman.pb(a[i]);
            else if(a[i].virtue >= a[i].talent)
                foolman.pb(a[i]);
            else
                other.pb(a[i]);
        }
    }

    cout<<sage.size()+nobleman.size()+foolman.size()+other.size()<<endl;

    for(auto t:sage)
        cout<<t.id<<' '<<t.virtue<<' '<<t.talent<<endl;
    for(auto t:nobleman)
        cout<<t.id<<' '<<t.virtue<<' '<<t.talent<<endl;
    for(auto t:foolman)
        cout<<t.id<<' '<<t.virtue<<' '<<t.talent<<endl;
    for(auto t:other)
        cout<<t.id<<' '<<t.virtue<<' '<<t.talent<<endl;
    //system("pause");
    return 0;
}

晴神的写法:

const int N=1e5+10;
struct Node
{
    string id;
    int virtue,talent;
    int total;
    int level;
    bool operator<(const Node &W) const
    {
        if(level == W.level)
        {
            if(total == W.total)
            {
                if(virtue == W.virtue)
                    return id<W.id;
                else return virtue > W.virtue;
            }
            else return total > W.total;
        }
        else return level < W.level;
    }
}a[N];
int n,lowest,highest;

bool check(int a,int b)
{
    return a>=lowest && b>=lowest;
}

int main()
{
    cin>>n>>lowest>>highest;

    int cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].id>>a[i].virtue>>a[i].talent;
        a[i].total=a[i].virtue+a[i].talent;
        if(check(a[i].virtue,a[i].talent))
        {
            cnt++;
            if(a[i].virtue >= highest && a[i].talent >= highest)
                a[i].level=1;
            else if(a[i].virtue >= highest)
                a[i].level=2;
            else if(a[i].virtue >= a[i].talent)
                a[i].level=3;
            else
                a[i].level=4;
        }
        else a[i].level=5;
    }

    sort(a,a+n);

    cout<<cnt<<endl;
    for(int i=0;i<cnt;i++)
        cout<<a[i].id<<' '<<a[i].virtue<<' '<<a[i].talent<<endl;

    //system("pause");
    return 0;
}

标签:25,total,Talent,int,1062,else,virtue,talent,highest
来源: https://www.cnblogs.com/fxh0707/p/14401717.html