我的做法很直接,在最后查找时候应该可以优化一下
本题无坑点,照意思做就行
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=100010;
struct node
{
char name[10];
int age ,worth;
}a[maxn];
bool cmp(node b,node c)
{
if(b.worth!=c.worth)return b.worth>c.worth;
else if (b.age!=c.age)return b.age<c.age;
else return strcmp(b.name,c.name)<0;
}
int main()
{
int n,k;
cin>>n>>k;
for (int i=0;i<n;i++)
{
scanf("%s %d %d",a[i].name,&a[i].age,&a[i].worth);
}
sort(a,a+n,cmp);
for (int i=0;i<k;i++)
{
int num,temp=0,min,max;
bool flag=false;
scanf("%d %d %d",&num,&min,&max);
printf("Case #%d:\n",i+1);
for (int j=0;j<n;j++)
{
if(temp==num)
break;
if (a[j].age>=min&&a[j].age<=max)
{
printf("%s %d %d\n",a[j].name,a[j].age,a[j].worth);
temp++;
flag=true;
}
}
if (flag==false)
{
printf("None\n");
}
}
}