求助

P1093 [NOIP2007 普及组] 奖学金

prophetcoding @ 2023-08-17 19:49:58

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

为什么判断条件放在函数外不行


by Chun_My @ 2023-08-19 16:00:13

写cmp里不香吗


by Chun_My @ 2023-08-19 16:00:24

@prophetcoding


|