80求助

P5740 【深基7.例9】最厉害的学生

qwcdim @ 2021-02-15 13:57:07

#include<iostream>
#include<cstring>
#include<string> 
#include<algorithm>
using namespace std;
struct hhh{
    string s;
    int yu,shu,yin;
    int zf;
    int ans;
}a[1001];
int n;
bool cmp(hhh a,hhh b){
    if(a.zf!=b.zf)return a.zf>b.zf;
    else a.ans<b.ans;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].s>>a[i].yu>>a[i].shu>>a[i].yin;
        a[i].zf=a[i].shu+a[i].yin+a[i].yu;
        a[i].ans=i;
    }
    sort(a+1,a+n+1,cmp);
    cout<<a[1].s<<" "<<a[1].yu<<" "<<a[1].shu<<" "<<a[1].yin;
    return 0;
}

输入:3 yyt 100 100 100 aaa 100 100 100 yyy 100 100 100

标准输出:yyt 100 100 100

我的输出:yyy 100 100 100


by _caiji_ @ 2021-02-15 13:58:46

if(a.zf!=b.zf)return a.zf>b.zf;
    else a.ans<b.ans;

您的 else 没 return。


by qwcdim @ 2021-02-15 14:00:48

啊~~~~ 谢了


|