题解 | #成绩排序#

成绩排序

http://www.nowcoder.com/practice/7a2f7d304d9e43b1bb2a6e72ed65bf51

//结构体重载运算符即可
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

int n;
struct Stu {
    string name;
    int age,grade;
    bool operator<(const Stu &t) const{
        if(grade!=t.grade) return grade<t.grade;
        else if(name!=t.name) return name<t.name;
        return age<t.age;
    }
};

int main(){
    cin>>n;
    vector<Stu> list;
    for(int i=0;i<n;i++){
        string name;
        int a,g;
        cin>>name>>a>>g;
        list.push_back({name,a,g});
    }
    sort(list.begin(),list.end());
    for(auto &[k,q,v]:list){
        cout<<k<<' '<<q<<' '<<v<<endl;
    }
    return 0;
}

全部评论

相关推荐

06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务