Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
436407 顾鑫辰 【C5-10】期末考试成绩排名 C++ 通过 100 2 MS 252 KB 908 2026-04-14 16:44:44

Tests(2/2):


#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; }


测评信息: