题解 | 成绩排序

成绩排序

https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7

#include<stdio.h>
#include<algorithm>
#include <vector>

using namespace std;
struct Student{
    int id;
    int score;
};
bool compare_sort(Student lhs,Student rhs){
    if(lhs.score<rhs.score){
        return true;
    }else if(lhs.score==rhs.score&&lhs.id<rhs.id){
        return true;
    }else{
        return false;
    }
}

int main() {
    int n;
    scanf("%d",&n);
    vector<Student> vec(n);
    for(int i=0;i<n;++i){
        scanf("%d%d",&vec[i].id,&vec[i].score);

    }
    sort(vec.begin(), vec.end(), compare_sort);
    for(int i=0;i<n;++i){
        printf("%d %d\n",vec[i].id,vec[i].score);
    }
    return 0;
}

全部评论
点赞 回复 分享
发布于 2025-03-11 16:47 江苏

相关推荐

评论
点赞
收藏
分享

创作者周榜

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