文章

6

粉丝

135

获赞

4

访问

14.0k

头像
小坑的地方在于,必须要初始化一个student,然后push_back.
P1159 清华大学上机题
发布于2023年3月20日 00:42
阅读数 2.0k

#include <bits/stdc++.h>
using namespace std;
struct Student{
    int id;
    int score;
};
bool cmp(Student x1, Student x2){
    if(x1.score == x2.score) return x1.id < x2.id;
    else{return x1.score < x2.score;}
}

int main(){
    int n;
    while(scanf("%d",&n) != EOF){
        vector<Student> stu;
        for(int i=0; i<n; ++i){
            Student a;
            scanf("%d %d",&a.id,&a.score);
            stu.push_back(a);
        }
        stable_sort(stu.begin(), stu.end(), cmp);
        for(int i=0;i<n;++i){
            printf("%d %d\n",stu[i].id,stu[i].score);
        }
    }
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发