文章

94

粉丝

0

获赞

455

访问

14.8k

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

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

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

int main()
{
     int num,order;
    while(cin >> num >> order){
        vector<Student> stu;
        int c = 0;
        for(int i = 0; i < num; i++){
            string name;
            int score;
            cin >> name >> score;
            stu.push_back({name, score,++c});
        }
...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发