???

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

yuguoyu @ 2021-11-19 15:43:40

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
struct hehe{
    char ming[100];
    int yuwen;
    int shuxue;
    int yingyu;
    int zong;
    int haoma; 
} a[1110];
int t(struct hehe a,struct hehe b)
{
    if(a.zong==b.zong)
        return a.haoma<b.haoma;
    else
        return a.zong>b.zong;
}
int main() 
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%s",a[i].ming);
        scanf("%d",&a[i].yuwen);
        scanf("%d",&a[i].shuxue);
        scanf("%d",&a[i].yingyu);
    }
    for(int i=0;i<n;i++)
    {
        a[i].zong=a[i].yuwen+a[i].shuxue+a[i].yingyu;
    }
    sort(a,a+n,t);
    cout<<a[0].ming<<" "<<a[0].yuwen<<" "<<a[0].shuxue<<" "<<a[0].yingyu<<endl;
    return 0;     
}

by L_sdcs @ 2021-11-19 15:46:38

你的haoma变量未赋值


by yuguoyu @ 2021-11-19 15:55:52

@L_sdcs 感谢!


by yuguoyu @ 2021-11-19 15:57:21

我AC了


|