题解 | 成绩排序
#include <bits/stdc++.h>
using namespace std;
struct s{
int p,q;
};
bool cmp(s a,s b){
if(a.q == b.q) return a.p<b.p;
else return a.q<b.q;
}
int main() {
int n;
cin>>n;
s stu[n+1];
for(int i=0;i<n;i++){
cin>>stu[i].p>>stu[i].q;
}
sort(stu,stu+n,cmp);
for(int i=0;i<n;i++){
cout<<stu[i].p<<" "<<stu[i].q<<endl;
}
}
// 64 位输出请用 printf("%lld")
查看11道真题和解析