排序 pat1062

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxv = 1e5 +5;
int n,L,H;
struct Stu{
       char id[10];//因为8位数 的id 所以不能直接用int存然后直接比大小?
       int a;
       int b;
       int sum;
       int type;
}stu[maxv];

bool cmp(Stu a, Stu b){
       if(a.type != b.type) return a.type < b.type; //按类型
       else if(a.sum != b.sum) return a.sum > b.sum;//按总分
       else if(a.a != b.a) return a.a > b.a;//按照德分
       else  return strcmp(a.id,b.id) < 0;//按照序号
}

int main()
{
       scanf("%d%d%d",&n,&L,&H);
       int m = n;//及格人数
       for(int i = 0; i < n; i++){
              scanf("%s %d %d", &stu[i].id, &stu[i].a, &stu[i].b);
              stu[i].sum = stu[i].a + stu[i].b;
              if(stu[i].a < L || stu[i].b < L){
                     stu[i].type = 5;
                     m--;
              }else if(stu[i].a >= H && stu[i].b >= H){
                     stu[i].type = 1;
              }else if(stu[i].a >= H && stu[i].b < H){
                     stu[i].type = 2;
              }else if( stu[i].a >= stu[i].b){//注意是德分 不低于才分!!所以包括等于
                     stu[i].type = 3;
              }else {
                     stu[i].type = 4;
              }
       }
       sort(stu, stu + n, cmp);
       printf("%d\n", m);
       for(int i = 0; i < m; i++){
              printf("%s %d %d\n", stu[i].id, stu[i].a, stu[i].b);
       }
    //cout << "Hello world!" << endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值