文章

34

粉丝

0

获赞

356

访问

7.9k

头像
成绩再次排序 题解:
P1817 华南理工大学机试题
发布于2026年3月10日 00:07
阅读数 94

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

struct Student{
    char name[1000];
    int s_Chinese;
    int s_Math;
    int s_English;
}stu[1000];

bool cmp(Student a,Student b){
    int sum_a=a.s_Chinese+a.s_Math+a.s_English;
    int sum_b=b.s_Chinese+b.s_Math+b.s_English;
    if(sum_a==sum_b) {
        if(a.s_Chinese==b.s_Chinese){
            if(a.s_Math==b.s_Math){
                if(a.s_English==b.s_English) return false;
                else return a.s_English>b.s_English;
            }
            else return a.s_Math>b.s_Math;
        }
        else return a.s_Chinese>b.s_Chinese;
    }
    else return sum_a>sum_b;
}

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++){
            scanf("%s %d %d %d",stu[i].name,&stu[i].s_Chinese,&stu[i].s_Math,&stu[i].s_English);
        }
        stable_sort(stu,stu+n,cmp);
        for(int i=0;i<n;i++){
            printf("...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发