对输入进行存储排序,然后对排好序的人进行处理,使其进入目标队列中
#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);
}
}