Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
110957 | 汤奕硕 | 成绩排序 | C++ | Accepted | 1 MS | 276 KB | 892 | 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; }