P1093 奖学金

P1093 奖学金

题目链接:https://www.luogu.org/problem/P1093

思路:

​ 该题可以使用结构体加sort排序。

代码:

#include <bits/stdc++.h>
using namespace std;

typedef struct pri
{
    int z,y,h;
}pri;
pri c[500];

bool cmp(pri a,pri b)  //先按照总成绩从大到小,再按照语文成绩从大到小,最后按照序号从小到大;
{
    if(a.z == b.z){  
        if(a.y == b.y){
            return a.h<b.h;
        }else{
            return a.y>b.y;
        }
    }else{
        return a.z>b.z;
    }
}
int main()
{
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,a,b,d,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d",&a,&b,&d);
        c[i].z = a+b+d;
        c[i].y = a;
        c[i].h = i+1;
    }
    sort(c,c+n,cmp);
    for(i=0;i<5;i++){
        printf("%d %d\n",c[i].h,c[i].z);
    }
    return 0;
}
posted @ 2019-08-01 22:37  幽灵小一只  阅读(169)  评论(0编辑  收藏  举报