#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct node
{
char id[20];
int age;
int worth;
}T[100005];
bool cmp(node a,node b)
{
if(a.worth!=b.worth)
return a.worth > b.worth;
else if(a.age!=b.age)
return a.age < b.age;
else
return strcmp(a.id,b.id) < 0;
}
int main()
{
// freopen("in.txt","r",stdin);
int N,K;
scanf("%d %d",&N,&K);
for(int i=0;i<N;i++)
scanf("%s %d %d",T[i].id,&T[i].age,&T[i].worth);
sort(T,T+N,cmp);
for(int i=1;i<=K;i++)
{
int m,l,r;
scanf("%d %d %d",&m,&l,&r);
printf("Case #%d:\n",i);
int cou=0;
for(int j=0;j<N;j++)
{
if(cou<m)//人数未满
{
if(T[j].age>=l && T[j].age<=r)
{
printf("%s %d %d\n",T[j].id,T[j].age,T[j].worth);
cou++;
}
}
else
break;
}
if(cou==0)
printf("None\n");
}
return 0;
}
1055. The World's Richest (25)
最新推荐文章于 2021-08-22 16:32:31 发布
本文展示了一个使用C++编写的程序,该程序读取输入数据并根据特定条件对人员信息进行排序。首先按照财富从高到低排序,如果财富相同,则按年龄从小到大排序,若年龄也相同则按ID字母序排序。程序使用了结构体和自定义比较函数实现复杂条件下的排序。

732

被折叠的 条评论
为什么被折叠?



