求解答

P1093 [NOIP2007 普及组] 奖学金

ZMTZHT519 @ 2023-12-10 15:10:24

#include<bits/stdc++.h>
using namespace std;
int n;
struct s{
    int a;
    int d;//总分
    int id; 
}xx[105];
int comp(s j,s q){
    if(j.d!=q.d){
        return j.d>q.d;
    }
    if(j.a!=q.a){
        return j.a>q.a;
    }
    return j.id>q.id;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int b,c;
        cin>>xx[i].a>>b>>c;
        xx[i].d=xx[i].a+b+c;
        xx[i].id=i;
    } 
    sort(,,comp);
    for(int i=1;i<=5;i++){
        cout<<xx[i].id<<" "<<xx[i].d<<endl;
    }
    return 0;
}

by lzj20110120 @ 2023-12-10 15:23:05

#include <bits/stdc++.h>
using namespace std;
int n,ans;

struct grade{
    int num,c,m,e;
} a[310];

bool cmp(grade a,grade b) {
    int tmp1=a.c+a.e+ a.m;
    int tmp2=b.c+ b.e+ b.m;
    if (tmp1==tmp2)
        if (a.c!=b.c)
            return a.c>b.c;
        else
            return a.num<b.num;
    return tmp1>tmp2;

}

int main() {
    cin>>n;
    for(int i=0;i<n;i++){
        a[i].num= i + 1;
        cin >> a[i].c>> a[i].m>> a[i].e;
    }
    sort(a, a + n, cmp);
    for (int i = 0; i < 5; i++) {
        cout << a[i].num<< ' ' << a[i].c+ a[i].e+ a[i].m<<endl;
    }

    return 0;
}

by ZMTZHT519 @ 2023-12-10 15:51:53

谢谢


|