题目:https://www.patest.cn/contests/pat-a-practise/1055
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct rich{
char name[10];
int age;
int wealth;
}s[100010],sele[100010];
int age[100010]={0};
bool cmp(rich a,rich b){
if(a.wealth!=b.wealth) return a.wealth>b.wealth;
else if(a.age!=b.age) return a.age<b.age;
else return strcmp(a.name,b.name)<0;
}
int main()
{
int m,n;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++){
scanf("%s%d%d",&s[i].name,&s[i].age,&s[i].wealth);
}
sort(s,s+n,cmp);
int t=0;
for(int i=0;i<n;i++){
if(age[s[i].age]<100){
age[s[i].age]++;
sele[t++]=s[i];
}
}
int temp,min,max;
for(int i=1;i<=m;i++){
scanf("%d%d%d",&temp,&min,&max);
printf("Case #%d:\n",i);
int count=0;
for(int j=0;j<t&&count<temp;j++){
if(sele[j].age>=min&&sele[j].age<=max){
printf("%s %d %d\n",sele[j].name,sele[j].age,sele[j].wealth);
count++;
}
}
if(count==0){
printf("None\n");
}
}
system("pause");
}