P1093 [NOIP2007 普及组] 奖学金

题目传送门

#include <bits/stdc++.h>

using namespace std;
const int N = 310;
int n;
struct Student {
    int id, chinese, total;
} a[N];

bool cmp(const Student &a, const Student &b) {
    if (a.total == b.total) {
        if (a.chinese == b.chinese) return a.id < b.id;
        else return a.chinese > b.chinese;
    } else
        return a.total > b.total;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int math, english;
        cin >> a[i].chinese >> math >> english;
        a[i].total = a[i].chinese + math + english;
        a[i].id = i + 1;
    }
    sort(a, a + n, cmp);
    for (int i = 0; i < 5; i++)
        cout << a[i].id << " " << a[i].total << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/littlehb/p/15593087.html