1055. The World's Richest (25)

对输入进行存储排序,然后对排好序的人进行处理,使其进入目标队列中

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#pragma warning (disable :4996)
using namespace std;
struct node {
    string name;
    int age, worth;
    bool operator<(const node that) const {
        if (this->worth > that.worth ||
            (this->worth == that.worth && this->age < that.age) ||
            (this->worth == that.worth && this->age == that.age && this->name < that.name))
            return true;
        return false;
    }
};
vector<node> all;           //存储输入,并继续排序
struct resault {            //结果节点
    vector<node> people;
    int l, r;
    int num;
};
vector<resault> rr; //存储结果
int N, K;
int main()
{
    cin >> N >> K;
    rr.resize(K);
    all.resize(N);
    for (int t = 0;t < N;t++)
    {
        char a[10];
        scanf("%s %d %d", a, &all[t].age, &all[t].worth);
        all[t].name = a;
    }
    sort(all.begin(), all.end());
    for (int t = 0;t < K;t++)
        scanf("%d %d %d", &rr[t].num, &rr[t].l, &rr[t].r);
    for (auto x : all)  //对每一个输入节点进行处理
    {
        for (auto &y : rr)
        {
            if ( y.num == y.people.size()) continue;
            if (x.age >= y.l && x.age <= y.r) y.people.push_back(x);
        }
    }
    for (int t = 0;t < K;t++)//输出结果
    {
        printf("Case #%d:\n",t+1);
        if (rr[t].people.size() == 0)printf("None\n");
        else
            for (auto x : rr[t].people)
                printf("%s %d %d\n", x.name.c_str(), x.age, x.worth);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值