题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include <iostream> #include <algorithm> using namespace std; struct Student { int id; int score; }; Student stu[101]; bool compare (Student x ,Student y){ if (x.score == y.score){ return x.id < y.id; } return x.score < y.score; } int main () { int n; while (cin >> n){ for (int i = 0; i < n; i++){ cin >> stu[i].id >> stu[i].score; } sort (stu, stu + n, compare); for (int i = 0; i < n; i++){ cout << stu[i].id << " " << stu[i].score << endl; } } return 0; }