3010 奖学金2 结构体 排序基础

 

#include<bits/stdc++.h>
using namespace std;
struct node{
    int yw,sx,yy,zf,id;
};
node a[301];
bool comp(node a,node b)
{
       //总分高优先,总分相同,语文成绩高优先,语文相同,顺序小优先
    if(a.zf==b.zf){
        if(a.yw==b.yw)return a.id<b.id;
        else return a.yw>b.yw;
    }
    else return a.zf>b.zf;
}
int main()
{
    //1.定义变量
    int n;
    //2.输入数据 
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].yw>>a[i].sx>>a[i].yy;
        a[i].id = i;
        a[i].zf = a[i].yw+a[i].sx+a[i].yy;
    }
    sort(a+1,a+1+n,comp);
    for(int i=1;i<=5;i++)
        cout<<a[i].id<<" "<<a[i].zf<<endl;
     return 0;
}

 

posted @ 2024-06-28 17:30  CRt0729  阅读(47)  评论(0编辑  收藏  举报