题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include<iostream> #include<algorithm> using namespace std; const int N = 110; struct Stu { int id; int score; } s[N]; bool cmp(Stu s1, Stu s2) { if (s1.score == s2.score) return s1.id < s2.id; return s1.score < s2.score; } int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i].id >> s[i].score; } sort(s, s + n, cmp); for (int i = 0; i < n; i++) { printf("%d %d\n", s[i].id, s[i].score); } return 0; }