Run ID:110957

提交时间:2025-02-24 19:42:02

#include <iostream> #include <vector> #include <algorithm> // 用于 sort using namespace std; struct Student { string name; int score; }; // 比较函数,先按成绩从高到低,再按名字字典序从小到大 bool compare(const Student &a, const Student &b) { if (a.score == b.score) { return a.name < b.name; } return a.score > b.score; } int main() { int n; cin >> n; // 读取学生数目 vector<Student> students(n); for (int i = 0; i < n; ++i) { cin >> students[i].name >> students[i].score; // 读取每个学生的名字和成绩 } // 按照比较函数排序 sort(students.begin(), students.end(), compare); // 输出排序后的成绩单 for (int i = 0; i < n; ++i) { cout << students[i].name << " " << students[i].score << endl; } return 0; }