#include #include using namespace std;

struct Student{ string name; int chinese; int math; int english; int sum; int id; };

bool cmp(Student a, Student b){ if(a.sum != b.sum){ return a.sum > b.sum; } else if(a.chinese != b.chinese){ return a.chinese > b.chinese; } else if(a.math != b.math){ return a.math > b.math; } else if(a.english != b.english){ return a.english > b.english; } else{ return a.id < b.id; } }

int main(){ int n; cin >> n; Student stu[n]; for(int i = 0; i < n; i++){ cin >> stu[i].name >> stu[i].chinese >> stu[i].math >> stu[i].english; stu[i].sum = stu[i].chinese + stu[i].math + stu[i].english; stu[i].id = i + 1; } sort(stu, stu+n, cmp); for(int i = 0; i < 5; i++){ cout << stu[i].name << " " << stu[i].sum << endl; } return 0;

用c++写出这道题:题目描述按学号从小到大给出一个班 n 个同学的语数英成绩请计算他们的总分并根据总分输出前5名同学的姓名和总分如果总分相同则语文成绩高者排名靠前;如果语文成绩相同则数学成绩高者排名靠前;如果数学成绩相同则英语成绩高者排名靠前;若英语成绩相同则学号小的排名靠前输入格式第一行输入一个正整数 n5 ≤ n ≤ 50代表班级学生人数。接下来的n 行每行包含四个数据:姓名 语文成绩 数学成

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

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