题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include <bits/stdc++.h> using namespace std; struct stu{ int id; int score; }; int cmp(stu a,stu b){ if(a.score == b.score) return a.id < b.id; else return a.score < b.score; } int main() { int n; while(cin >> n){ vector<stu> s(n); for(int i = 0 ; i < n ; i ++){ cin >> s[i].id >> s[i].score; } stable_sort(s.begin(),s.end(),cmp); for(int i = 0 ; i < n ; i++){ cout << s[i].id << " " << s[i].score << endl; } } }
模板题 没什么多说的