总是少输出1个求调

P1093 [NOIP2007 普及组] 奖学金

wenyuhao120806 @ 2025-01-12 16:47:23

include <bits/stdc++.h>

using namespace std;

struct stu{

int yu,shu,ying,zf,id

; }a[302];

#include <bits/stdc++.h>
using namespace std;
struct stu{
    int yu,shu,ying,zf,id;
    }a[302];
int cmp(stu a,stu b){
    if(a.zf!=b.zf){
        return a.zf>b.zf; 
    }else if(a.yu!=b.yu){
        return a.yu>b.yu;
    }else{
        return a.id<b.id;
    }
} 
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].yu>>a[i].shu>>a[i].ying;
        a[i].zf=a[i].yu+a[i].shu+a[i].ying;
        a[i].id=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<5;i++){
        cout<<a[i].id<<' '<<a[i].zf<<endl;
    }
    return 0;
}

int cmp(stu a,stu b){

if(a.zf!=b.zf){

    return a.zf>b.zf; 

}else if(a.yu!=b.yu){

    return a.yu>b.yu;

}else{

    return a.id<b.id;

}

} int main(){

int n;
cin>>n;
for(int i=1;i<=n;i++){
    cin>>a[i].yu>>a[i].shu>>a[i].ying;
    a[i].zf=a[i].yu+a[i].shu+a[i].ying;
    a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<5;i++){
    cout<<a[i].id<<' '<<a[i].zf<<endl;
}
return 0;

}


by wangjiawen @ 2025-01-12 16:50:16

希丰展,使md@wenyuhao120806


by wangjiawen @ 2025-01-12 16:59:47

for(int i=1;i<5;i++)

你一共就执行四遍,怎么可能输出5个呢哥们


by wangjiawen @ 2025-01-12 16:59:56

@wenyuhao120806


|