pat 乙级 1015. 德才论(25)



注意 : 用cout cin 这道题容易超时  建议用scanf printf


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
struct node {
    int num;
    int de;
    int cai;
};
int cmp(struct node a, struct node b) {
    if ((a.de + a.cai) != (b.de + b.cai)) {
        return (a.de + a.cai) > (b.de + b.cai);
    }else if (a.de != b.de) {
        return a.de > b.de;
    } else
        return a.num < b.num;
}
int main() {
    int n, low, high;
    scanf("%d %d %d", &n, &low, &high);
    vector<node> a, b, c, d;
    node temp;
    int total = n;
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &temp.num, &temp.de, &temp.cai);
        if (temp.de < low || temp.cai < low) {
            total--;
            continue;
        }
        if (temp.de >= high && temp.cai >= high) {
            a.push_back(temp);
        } else if (temp.de >= high && temp.cai < high) {
            b.push_back(temp);
        } else if (temp.de < high && temp.cai < high && temp.de >= temp.cai) {
            c.push_back(temp);
        } else {
            d.push_back(temp);
        }
    }
    sort(a.begin(), a.end(), cmp);
    sort(b.begin(), b.end(), cmp);
    sort(c.begin(), c.end(), cmp);
    sort(d.begin(), d.end(), cmp);
    printf("%d\n", total);
    for(int i = 0; i < a.size(); i++)
        printf("%d %d %d\n", a[i].num, a[i].de, a[i].cai);
    for(int i = 0; i < b.size(); i++)
        printf("%d %d %d\n", b[i].num, b[i].de, b[i].cai);
    for(int i = 0; i < c.size(); i++)
        printf("%d %d %d\n", c[i].num, c[i].de, c[i].cai);
    for(int i = 0; i < d.size(); i++)
        printf("%d %d %d\n", d[i].num, d[i].de, d[i].cai);
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值