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

struct Student {
    int id;
    int chinese;
    int math;
    int english;
    int total;
};

bool compare(const Student& s1, const Student& s2) {
    if (s1.total != s2.total) {
        return s1.total > s2.total;
    } else if (s1.chinese != s2.chinese) {
        return s1.chinese > s2.chinese;
    } else {
        return s1.id < s2.id;
    }
}

int main() {
    int n;
    cin >> n;
    
    vector<Student> students(n);
    for (int i = 0; i < n; i++) {
        cin >> students[i].chinese >> students[i].math >> students[i].english;
        students[i].id = i + 1;
        students[i].total = students[i].chinese + students[i].math + students[i].english;
    }
    
    sort(students.begin(), students.end(), compare);
    
    for (int i = 0; i < 5; i++) {
        cout << students[i].id << " " << students[i].total << endl;
    }
    
    return 0;
}
``
题目描述某小学最近得到了一笔赞助打算拿出其中一部分为学习成绩优秀的前 55 名学生发奖学金。期末每个学生都有 33 门课的成绩:语文、数学、英语。先按总分从高到低排序如果两个同学总分相同再按语文成绩从高到低排序如果两个同学总分和语文成绩都相同那么规定学号小的同学排在前面这样每个学生的排序是唯一确定的。任务:先根据输入的 33 门课的成绩计算总分然后按上述规则排序最后按排名顺序输出前 55 名学生的

原文地址: http://www.cveoy.top/t/topic/iIyx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录