90分求助

P1093 [NOIP2007 普及组] 奖学金

DYC_YYDS @ 2023-10-05 08:32:04

代码



#include<bits/stdc++.h>
using namespace std;
struct stu{
    int a,b,c,d,e;
}an[301];
bool p(stu x,stu y){
    if(x.e!=y.e){
        return x.e>y.e;
    }else if(x.a!=y.a){
        return x.b>y.b;
    }return x.a<y.a;
}
int main(){
    int f;
    cin>>f;
    for(int i=0;i<f;i++){
        cin>>an[i].b>>an[i].c>>an[i].d;
        an[i].a=i;
        an[i].e=an[i].b+an[i].c+an[i].d;

    }sort(an,an+f,p);
    for(int i=0;i<5;i++){
        cout<<an[i].a+1<<" "<<an[i].e<<endl;
    }
}

by littlesnake @ 2023-10-18 17:10:40

#include <bits/stdc++.h>
using namespace std;
const int N=310;
struct node{
    //num:学号
    //因为排序会改变顺序
    //所以学号要提前记下来 
    //sum:总分 
    int num,x,y,z,sum;
}a[N];
int n;
//按题目所给的规则排序 
bool cmp(node n1,node n2){
    if(n1.sum!=n2.sum){
        return n1.sum>n2.sum;
    }else{
        if(n1.x!=n2.x){
            return n1.x>n2.x;
        }else{
            return n1.num<n2.num;
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].z);
        a[i].num=i;
        a[i].sum=a[i].x+a[i].y+a[i].z;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++){
        printf("%d %d\n",a[i].num,a[i].sum);
    }
    return 0;
}

和我写的差不多


|