码迷,mamicode.com
首页 > 其他好文 > 详细

1015 德才论

时间:2020-02-15 21:51:58      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:can   include   algorithm   for   数据   return   col   bsp   style   

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

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 德才论

标签:can   include   algorithm   for   数据   return   col   bsp   style   

原文地址:https://www.cnblogs.com/keep23456/p/12313855.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!