求助,50分!!!

P1093 [NOIP2007 普及组] 奖学金

Legendre @ 2020-02-02 20:34:02

#include<iostream>
#include<algorithm>
using namespace std;
struct stu{
    int num;
    int chi,mat,eng; 
    int s;
}a[310];
bool cmp(stu a,stu b){
     return a.s>b.s;
    return a.chi>b.chi;
    return a.num<b.num;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++){
        a[i].num=i;
        cin>>a[i].chi>>a[i].mat>>a[i].eng;
        a[i].s=a[i].chi+a[i].mat+a[i].eng;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1; i<=5; i++)
        cout<<a[i].num<<" "<<a[i].s<<endl;

    return 0;
}

求助,50分,前五个点A了,后五个点哇(WA)了


by MiEcoku @ 2020-02-02 20:50:31

给个数据自己找找 5 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0


by MiEcoku @ 2020-02-02 20:50:55

嗯,我换行怎么阵亡了?


by y0y68 @ 2020-02-02 21:02:41

#include<algorithm>
using namespace std;
struct stu{
    int num;
    int chi,mat,eng; 
    int s;
}a[310];
bool cmp(stu a,stu b){
    if(a.s!=b.s)return a.s>b.s;
    if(a.chi!=b.chi)return a.chi>b.chi;
    return a.num<b.num;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++){
        a[i].num=i;
        cin>>a[i].chi>>a[i].mat>>a[i].eng;
        a[i].s=a[i].chi+a[i].mat+a[i].eng;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1; i<=5; i++)
        cout<<a[i].num<<" "<<a[i].s<<endl;
    return 0;
}

加上if(a.s!=b.s)和if(a.chi!=b.chi)就可以了


by Legendre @ 2020-02-03 14:34:03

谢各位大佬~


|