1015 德才论

Posted keep23456

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1015 德才论相关的知识,希望对你有一定的参考价值。

 没啥好说的,按题意对数据排序输出即可。

STL:vector,string.用cin/cout可能会超时,改成scanf和printf即可。

#include"iostream"
#include"algorithm"
#include"vector"
using namespace std;

struct Student {
    string id;
    int G1,G2,sum;
    int type;
} ;

bool cmp(const Student& a,const Student& b) {
    if(a.type != b.type) return a.type < b.type;
    else if(a.sum != b.sum) return a.sum > b.sum;
    else if(a.G1 != b.G1) return a.G1 > b.G1;
    else return a.id < b.id;
}
int main() {
    int N,L,H,g1,g2;
    string str;
    scanf("%d%d%d",&N,&L,&H);
    vector<Student> vec;
    Student stu;
    for(int i = 0; i < N; ++i) {
        cin>>str;
        scanf("%d%d",&g1,&g2);
        if(g1 >= L && g2 >= L) {
            stu.id = str;
            stu.G1 = g1;
            stu.G2 = g2;
            stu.sum = g1+g2;
            if(g1 >= H && g2 >= H ) stu.type = 1;
            else if(g1 >= H && g2 < H) stu.type = 2;
            else if(g1 <= H && g2 <= H && g1 >= g2) stu.type = 3;
            else stu.type = 4;
            vec.push_back(stu);
        }
    }
    sort(vec.begin(),vec.end(),cmp);
    cout<<vec.size()<<endl;
    for(auto it = vec.begin(); it != vec.end(); ++it)
        cout<<it->id<<" "<<it->G1<<" "<<it->G2<<endl;
    return 0;
}

 

以上是关于1015 德才论的主要内容,如果未能解决你的问题,请参考以下文章

PAT乙级1015-----德才论 (25分)

1015. 德才论 (25)

P 1015 德才论

Basic Level 1015 - 德才论

PAT1015 德才论 (25)(25 分)

1015 德才论 (25 分)