文章

17

粉丝

0

获赞

119

访问

4.3k

头像
成绩排序 题解:
P1151 清华大学上机题
发布于2025年2月28日 11:19
阅读数 291

#include <bits/stdc++.h>
using namespace std;

struct stu{
        string name;
        int num;
    };
    
bool cg(const stu& a,const stu& b){
        return a.num>b.num;
}
    
bool cl(const stu& a,const stu& b){
    return a.num<b.num;
}

int main() {
    int n,way;
    while(cin>>n){
        cin>>way;
        vector<stu> m(n);
        for(int i =0;i<n;i++) cin>>m[i].name>>m[i].num;

        if(way==0) stable_sort(m.begin(),m.end(),cg);
        else stable_sort(m.begin(),m.end(),cl);
    
        for(int i =0;i<n;i++) cout...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发