50分求解

P1093 [NOIP2007 普及组] 奖学金

W_R_Q @ 2024-07-20 09:50:25


by amd47802574 @ 2024-07-22 13:54:08

你什么都不说,怎么知道你错哪儿了


by W_R_Q @ 2024-07-22 16:02:56


#include<bits/stdc++.h>
using namespace std;
struct student{
    int xuehao;
    int zongfen;
    int yuwen;
    int shuxue;
    int yingyu;
}a[310];
int n;
int cmp(student one,student two){
    if(one.zongfen==two.zongfen){
        if(one.yuwen==two.yuwen){
            return one.xuehao<two.xuehao;
        }
        return one.yuwen>two.yuwen;
    }
    return one.zongfen>two.zongfen;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].yuwen>>a[i].shuxue>>a[i].yingyu;
        a[i].zongfen=a[i].yuwen+a[i].shuxue+a[i].yingyu;
        a[i].xuehao=i+1;
    }
    sort(a,a+n,cmp); 
    for(int i=0;i<5;i++){
        cout<<a[i].xuehao<<" "<<a[i].zongfen<<endl;
    }
    return 0; 
}
//刚解出来了 @[amd47802574](/user/1224587)

by amd47802574 @ 2024-07-22 17:06:09

比较器那里可以简写下,偷懒

struct node {
    int c, m, e, sum, no;
}m[301];

bool cmp(node p,node q)
{
    if (p.sum != q.sum) return p.sum > q.sum;
    else if (p.c != q.c) return p.c > q.c;
    return p.no < q.no;
}

by W_R_Q @ 2024-07-24 09:53:00

@amd47802574

xiexie!


|