题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool Compare(pair<int,int> a,pair<int,int> b){
if(a.second==b.second)
return a.first<b.first;
else
return a.second<b.second;
}
int main() {
int n;
while (cin >> n) { // 注意 while 处理多个 case
vector<pair<int,int>> student;
int no,score;
for(int i=0;i<n;i++){
cin>>no>>score;
student.push_back(make_pair(no,score));
}
sort(student.begin(),student.end(),Compare);
for(int i=0;i<n;i++){
cout<<student[i].first<<" "<<student[i].second<<endl;
}
}
}
// 64 位输出请用 printf("%lld")