90分求助

P1093 [NOIP2007 普及组] 奖学金

OutsideR_ @ 2020-10-21 15:42:22

大佬 怎么错了?

#include <iostream>
#include <algorithm>
using namespace std;
struct name{
    int number;
    int c,m,e,sum;
};
bool cpp(name a,name b){
    if(a.sum==b.sum){
        if(a.c==b.c){
            if(a.m==b.m){
                return a.e>b.e;
            }
            else{
                return a.m>b.m;
            }
        }
        else{
            return a.c>b.c;
        }
    }
    else{
        return a.sum>b.sum;
    }
}
int main(){
    short n;
    cin>>n;
    name arr[n+2];
    for(int i = 0;i<n;i++){
        cin>>arr[i].c>>arr[i].m>>arr[i].e;
        arr[i].sum=arr[i].c+arr[i].m+arr[i].e;
        arr[i].number=i+1;
    }
    sort(arr,arr+n,cpp);
    for(int i = 0;i<=4;i++){
        cout<<arr[i].number<<" "<<arr[i].sum<<endl;
    }
    return 0;
}

by 起名字很重要 @ 2020-10-21 18:33:21

@Cyc曹

#include<iostream>
#include<algorithm>
using namespace std;
struct stu
{
    int num;//编号
    int c,m,e; 
    int sum;
}student[310];
bool cmp(stu a,stu b)
{
    if(a.sum>b.sum) return 1;
    else if(a.sum<b.sum) return 0;
    else
    {
        if(a.c>b.c) return 1;
        else if(a.c<b.c) return 0;
        else
        {
            if(a.num>b.num) return 0;
            else return 1;
        }
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        student[i].num=i;//录入编号
        cin>>student[i].c>>student[i].m>>student[i].e;//输入
        student[i].sum=student[i].c+student[i].m+student[i].e;//计算总分
    }
    sort(student+1,student+1+n,cmp);
    for(int i=1;i<=5;i++)
        cout<<student[i].num<<' '<<student[i].sum<<endl;
    return 0;
}

by OutsideR_ @ 2020-10-25 17:52:45

oh大佬


by 单调欧文 @ 2020-11-02 21:46:22

@Cyc曹 他只和语文,总分,顺序有关。与数学和英语无关的


|