字节客户端永远缺人
2 3

相关推荐

2024-12-30 14:39
哈尔滨理工大学 C++
#include #include #include   // 用于排序using namespace std;// 定义学生结构体struct Student {    string name;       // 姓名    int programming;   // 编程成绩    int math;          // 数学成绩    int english;       // 英语成绩    // 计算总分    int totalScore() const {        return programming + math + english;    }};// 自定义排序规则bool compareStudents(const Student &a, const Student &b) {    if (a.totalScore() != b.totalScore()) { return a.totalScore() > b.totalScore();  // 按总分从高到低排序    } else {        return a.name     }}int main() {    int n; cin >> n;  // 读取学生数量    // 定义学生数组    Student students[n];    // 读取每个学生的信息    for (int i = 0; i  cin >> students[i].name >> students[i].programming >> students[i].math >> students[i].english;    }    // 对学生数组进行排序    sort(students, students + n, compareStudents);    // 输出排序后的学生姓名和总分    for (int i = 0; i         cout     }    return 0;}
点赞 评论 收藏
分享
2024-12-28 10:32
已编辑
门头沟学院 前端工程师
百度 前端开发 n*16+60
点赞 评论 收藏
分享
牛客网
牛客企业服务