1055. The World's Richest (25)

 1 #include <stdio.h>
 2 #include <vector>
 3 #include<string.h>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 struct MyStruct
 8 {
 9     char name[9];
10     int age,worth;
11 };
12 
13 int cmp(MyStruct a,MyStruct b)
14 {
15     if(a.worth!=b.worth) return a.worth>b.worth;
16     else
17     {
18         if(a.age!=b.age) return a.age<b.age;
19         else
20         {
21             return (strcmp(a.name,b.name)<0);
22         }
23     }
24 }
25 
26 int main()
27 {
28     int n,k,i,j,Max,low,high;
29     while(scanf("%d %d",&n,&k)!=EOF)
30     {
31         vector<MyStruct> vv;
32         for(i=0;i<n;i++)
33         {
34             getchar();
35             MyStruct tem;
36             scanf("%s %d %d",tem.name,&tem.age,&tem.worth);
37             vv.push_back(tem);
38         }
39 
40         sort(vv.begin(),vv.end(),cmp);
41 
42         vector<MyStruct> VV2;
43         int Age[201];
44         for(i=1;i<=200;i++)
45             Age[i]=0;
46 
47         for(i=0;i<n;i++)
48             if(Age[vv[i].age]<100)
49             {
50                 ++Age[vv[i].age];
51                 VV2.push_back(vv[i]);
52             }
53 
54         for(i=0;i<k;i++)
55         {
56             getchar();
57             scanf("%d %d %d",&Max,&low,&high);
58             printf("Case #%d:
",i+1);
59             
60             int printNum = 0;
61 
62             for(j=0;j<VV2.size() && printNum < Max ;j++)
63             {
64                 if( VV2[j].age >= low && VV2[j].age <= high )
65                 {
66                     printf("%s %d %d
",VV2[j].name,VV2[j].age,VV2[j].worth);
67                     ++printNum;
68                 }
69             }
70 
71             if(printNum==0) printf("None
");
72             
73         }
74     }
75    return 0;
76 }
原文地址:https://www.cnblogs.com/xiaoyesoso/p/4265170.html