题目传送门

#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;
}

相关文章:

  • 2022-12-23
  • 2021-11-09
  • 2021-09-18
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2021-06-15
  • 2021-07-12
相关资源
相似解决方案