90分求助

P1093 [NOIP2007 普及组] 奖学金

2013wjy @ 2024-01-06 21:34:46

#include<bits/stdc++.h>
using namespace std;
int n;
struct daxiao{
    int m;//学号 
    int z;//总分 
    int c_grade;//语文成绩 
};
daxiao s[301];
bool cmp(daxiao a,daxiao b){
    if(a.z!=b.z)return a.z<b.z;
    else{
        if(a.c_grade!=b.c_grade)return a.c_grade<b.c_grade;
        else{
            return a.m<b.m;
        }
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        s[i].z=a+b+c;
        s[i].c_grade=a;
        s[i].m=i;
    }
    sort(s,s+n,cmp);
    for(int i=0;i<5;i++){
        cout<<s[i].m<<' '<<s[i].z<<endl;
    }
    return 0;
}

by huangzhixia @ 2024-01-06 21:42:56

@2013wjy

#include<bits/stdc++.h>
using namespace std;
int n;
struct daxiao{
    int m;//学号 
    int z;//总分 
    int c_grade;//语文成绩 
};
daxiao s[301];
bool cmp(daxiao a,daxiao b){
    if(a.z!=b.z)return a.z>b.z;
    else{
        if(a.c_grade!=b.c_grade)return a.c_grade>b.c_grade;
        else{
            return a.m>b.m;
        }
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        s[i].z=a+b+c;
        s[i].c_grade=a;
        s[i].m=i;
    }
    sort(s,s+n,cmp);
    for(int i=0;i<5;i++){
        cout<<s[i].m + 1<<' '<<s[i].z<<endl;
    }
    return 0;
}

给你有以下几点建议:


|