WA在第八个点,90分,求大佬帮看一下,谢谢!

P1093 [NOIP2007 普及组] 奖学金

physics—LindseyWEI @ 2018-07-28 22:20:39

#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
int n;
struct node{
    int chi;
    int math;
    int e;
    int sum;
    int num;
}a[305];
bool cmp(node x,node y)
{
    if(x.sum!=y.sum)
    {
        return x.sum>y.sum;
    }
    else if(x.chi!=y.chi)
    {
        return x.chi>y.chi;
    }
    else
    {
        return x.num>y.num;
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].chi>>a[i].math>>a[i].e;
        a[i].sum=a[i].chi+a[i].math+a[i].e;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++)
    {
        cout<<a[i].num<<" "<<a[i].sum<<endl;
    }
    return 0;
} 

by dyyzy @ 2022-07-19 14:15:44

return x.num>y.num;

应改成

return x.num<y.num;


|