水题直接做。
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define maxn 100010
using namespace std;
struct people{
char name[20];
int age;
int worth;
}peo[maxn];
int m,Amin,Amax;
bool cmp(people a,people 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.name,b.name)<0;
}
int main()
{
int n,k;
scanf("%d%d",&n,&k);
getchar();
for(int i=0;i<n;++i)scanf("%s %d %d",peo[i].name,&peo[i].age,&peo[i].worth);
sort(peo,peo+n,cmp);
for(int i=0;i<k;++i)
{
scanf("%d%d%d",&m,&Amin,&Amax);
printf("Case #%d:\n",i+1);
bool lag=true;
int j=0;
int count=0;
for(;j<n;++j)
{
if(count>=m)break;
if(peo[j].age>=Amin&&peo[j].age<=Amax)
{
printf("%s %d %d\n",peo[j].name,peo[j].age,peo[j].worth);
lag=false;
count++;
}
}
if(lag)printf("None\n");
}
return 0;
}
全部测试点AC。
提交通过后,看书上答案发现要预处理一下,不然会超时?。。。。。。。
楼主没预处理居然过了。。。。。。
不管了,反正过了,继续下一题。