#include <iostream> #include <algorithm> #include <vector> using namespace std; struct Student { int id; string name; int score; }; // 比较函数,用于sort函数的排序规则 bool compare(Student a, Student b) { if (a.score != b.score) { return a.score > b.score; // 成绩降序 } return a.id < b.id; // 学号升序 } int main() { int n; cin >> n; vector<Student> students(n); // 读取学生信息 for (int i = 0; i < n; i++) { cin >> students[i].id >> students[i].name >> students[i].score; } // 排序 sort(students.begin(), students.end(), compare); // 输出排序后的学生信息 for (int i = 0; i < n; i++) { cout << students[i].id << " " << students[i].name << " " << students[i].score<<endl; } } /************************************************************** Problem: 1414 User: admin Language: C++ Result: Accepted Time:12 ms Memory:2088 kb ****************************************************************/