题解 | #成绩排序#

成绩排序

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

#include<iostream>
#include<algorithm>
using namespace std;

const int N = 110;

struct Stu {
    int id;
    int score;
} s[N];

bool cmp(Stu s1, Stu s2) {
    if (s1.score == s2.score) return s1.id < s2.id;
    return s1.score < s2.score;
}

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i].id >> s[i].score;
    }
    sort(s, s + n, cmp);

    for (int i = 0; i < n; i++) {
        printf("%d %d\n", s[i].id, s[i].score);
    }

    return 0;
}

全部评论

相关推荐

爱看电影的杨桃allin春招:我感觉你在炫耀
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务