90分求助

P1093 [NOIP2007 普及组] 奖学金

a_san_de_dou_li @ 2023-08-17 19:45:53

#include<bits/stdc++.h>
using namespace std;
struct san
{
    int c,m,e,z,h;
}a[1000];
bool cmp(san x,san y)
{
    if(x.z==y.z)
    {
        return x.c>y.c;
    }
    else
    {
        if(x.z==y.z)
        {
            return x.h<y.h;
        }
        else
        {
            return x.z>y.z;
        }
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].c>>a[i].m>>a[i].e;
        a[i].z=a[i].c+a[i].m+a[i].e;
        a[i].h=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++)
    {
        cout<<a[i].h<<" "<<a[i].z<<endl;
    }
    return 0;
}

by zhongxicheng @ 2023-08-17 20:36:16


bool cmp(san x,san y)
{
    if(x.z!=y.z)
        return x.z>y.z;
    if(x.c!=y.c)
        return x.c>y.c;
    return x.h<y.h;
}

懂?


by a_san_de_dou_li @ 2023-08-17 20:55:48

@zhongxicheng 懂,ac了,谢谢


|