文章

9

粉丝

0

获赞

15

访问

481

头像
成绩排序2.0 题解:c++ STL
P1159 清华大学上机题
发布于2026年2月2日 10:24
阅读数 38

#include<bits/stdc++.h>
using namespace std;
struct students{
     int num,score;
};

bool grade(const students&a,const students&b){
     if(a.score==b.score) return a.num<b.num;
     return a.score<b.score;
}
int main() {
    int n;
    cin>>n;
    if(n<1||n>100) return 0;
    vector<students> s(n);
    for(auto&i:s) cin>>i.num>>i.score;
    sort(s.begin(),s.end(),grade);
    for(auto &i:s) cout<<i.num<<" "<<i.score<<endl;
    return 0;
}
 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发