首页 > 代码库 > 1055. The World's Richest (25)
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 else17 {18 if(a.age!=b.age) return a.age<b.age;19 else20 {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:\n",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\n",VV2[j].name,VV2[j].age,VV2[j].worth);67 ++printNum;68 }69 }70 71 if(printNum==0) printf("None\n");72 73 }74 }75 return 0;76 }
1055. The World's Richest (25)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。