错了吗??!

P5740 【深基7.例9】最厉害的学生

asdfghjkl010218 @ 2022-04-09 17:04:12

#include<cstdio>
#include<iostream>
using namespace std;
string name[1005];
int cg[1005],mg[1005],eg[1005];
int main(){
    int n,max=-999999,t;
    scanf("%d",&n);
    for(int a=0;a<n;a++)cin>>name[a]>>cg[a]>>mg[a]>>eg[a];
    for(int b=0;b<n;b++){
        if(cg[b]+mg[b]+eg[b]>max){
            max=cg[b]+mg[b]+eg[b];
            t=b;
        }
    }
    cout<<name[t]<<" "<<cg[t]<<" "<<mg[t]<<" "<<eg[t];
}

by KAqwq @ 2022-04-09 17:08:16

所以为啥不用结构体+快排写


by C2024jitangle @ 2022-04-09 17:08:19

没错啊,反正我交上去是AC


by yanhaoxiang0814 @ 2022-05-13 13:43:26

@Kamisato_Ayato 这种方法怎么写


by KAqwq @ 2022-05-13 14:03:56

@yanhaoxiang0814

#define N 114514
struct node{
    int a;
    int b;
}x[N];//定义结构体
bool cmp(node x_,y_){
    return x_.a<y_.a;
}
sort(x+1,x+n+1,cmp);//快排

大概这样


by yanhaoxiang0814 @ 2022-05-13 16:05:43

@Kamisato_Ayato 谢谢


|