提交时间:2026-04-14 16:44:44

运行 ID: 436407

#include <iostream> #include <vector> #include <algorithm> using namespace std; // 定义学生结构体 struct Student { int id; // 学号 string name; // 姓名拼音 int score; // 数学成绩 }; // 排序规则:分数高到低,分数相同则学号小到大 bool cmp(const Student &a, const Student &b) { if (a.score != b.score) { return a.score > b.score; // 分数高的排前面 } else { return a.id < b.id; // 分数相同,学号小的排前面 } } int main() { int n; cin >> n; vector<Student> stu(n); for (int i = 0; i < n; i++) { cin >> stu[i].id >> stu[i].name >> stu[i].score; } // 排序 sort(stu.begin(), stu.end(), cmp); // 输出 for (auto s : stu) { cout << s.id << " " << s.name << " " << s.score << endl; } return 0; }