文章

34

粉丝

0

获赞

333

访问

6.0k

头像
成绩排序 - 华科 题解:
P1404 华中科技大学
发布于2026年3月9日 19:42
阅读数 68

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

struct Student{
    char name[100];
    int age;
    int score;
}stu[1000];

bool cmp(Student a,Student b){
    if((a.score==b.score)&&(strcmp(a.name,b.name)==0)) return a.age<b.age;
    if(a.score==b.score) return strcmp(a.name,b.name)<0;
    return a.score<b.score;
}

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++){
            scanf("%s %d %d",stu[i].name,&stu[i].age,&stu[i].score);
        }
        sort(stu,stu+n,cmp);
        for(int i=0;i<n;i++){
            printf("%s %d %d\n",stu[i].name,stu[i].age,stu[i].score);
        }
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发