-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpat 1055.cpp
72 lines (64 loc) · 1.92 KB
/
pat 1055.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct people
{
char name[9];
int age;
int worth;
}people;
people a[100000];
int N,K;
int agecount[201]={0};
int index1[100000];
int comp(const void *a,const void *b)
{
people *pa=(people *)a;
people *pb=(people *)b;
int r;
if( (r=pb->worth-pa->worth) != 0 )
return r;
if((r=pa->age-pb->age)!=0)
return r;
return strcmp(pa->name,pb->name);
}
int main()
{
int i,m,amin,amax,j,count,k,all,n2=0;
scanf("%d%d",&N,&K);
for(i = 0; i < N; i++)
{
getchar();
scanf("%s %d%d",a[i].name,&a[i].age,&a[i].worth);
}
qsort(a,N,sizeof(people),comp);
for(i = 0; i < N; i++)
if(++agecount[a[i].age]<=100)
index1[n2++]=i;
for(i = 0; i < K; i++)
{
scanf("%d%d%d",&m,&amin,&amax);
all=0;
for(k = amin; k <= amax ; k++)
all+=agecount[k];
printf("Case #%d:\n",i+1);
count=0;
m = all < m ? all : m;
if(all != 0)
{
for(j = 0; j < n2; j++)
{
if(a[index1[j].age <= amax && a[index1[j].age >= amin)
{
if(++count <= m)
printf("%s %d %d\n",a[index1[j].name,a[index1[j].age,a[index1[j].worth);
else
break;
}
}
}
if(count == 0)
printf("None\n");
}
return 0;
}