文章

94

粉丝

0

获赞

455

访问

14.8k

头像
成绩排序 题解:c++ ,用vector最好,用stable_sort实现稳定
P1151 清华大学上机题
发布于2026年2月8日 20:20
阅读数 183

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

struct Student{
    string name;
    int score;
};
bool cmp(Student a ,Student b){
    return a.score < b.score;
}
bool cmps(Student a ,Student b){
    return a.score > b.score;
}

int main()
{
     int num,order;
    while(cin >> num >> order){
        vector<Student> stu;
        for(int i = 0; i < num; i++){
            string name;
            int score;
            cin >> name >> score;
            stu.push_back({name, score});
        }
        if(order){
            stable_sort(stu.begin(),stu.end(),cmp);
        }else{
        &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发