PAT1055

  1. #include <iostream>  
  2. #include <fstream>  
  3. #include <algorithm>  
  4. #include <vector>  
  5. #include <cstring>  
  6. #include <cstdio>  
  7. using namespace std;  
  8.   
  9. //此代码使用前,需删除下面两行+后面的system("PAUSE")  
  10. ifstream fin("in.txt");  
  11. #define cin fin  
  12.   
  13. struct Person{  
  14.     char name[9];  
  15.     int age;  
  16.     int worth;  
  17. }*p;  
  18.   
  19. bool resCmp(const Person& a,const Person& b){  
  20.     if(a.worth == b.worth){  
  21.         if(a.age == b.age){  
  22.             if(strcmp(a.name,b.name)>0)  
  23.                 return false;  
  24.             else   
  25.                 return true;  
  26.         }else{  
  27.             return a.age < b.age;  
  28.         }  
  29.     }else{  
  30.         return a.worth > b.worth;  
  31.     }  
  32. }  
  33.   
  34. int main()  
  35. {  
  36.     int n,k;  
  37.     scanf("%d %d",&n,&k);  
  38.     //cin>>n>>k;  
  39.     p = new Person[n];  
  40.     int i,j,z;  
  41.     for(i=0;i<n;i++){  
  42.         scanf("%s %d %d",p[i].name,&p[i].age,&p[i].worth);  
  43.         //cin>>p[i].name>>p[i].age>>p[i].worth;  
  44.     }  
  45.     sort(p,p+n,resCmp);  
  46.     int ageCount[201]={0};  
  47.     int *filter = new int[n];  
  48.     int filter_num = 0;  
  49.     for(i=0;i<n;i++){  
  50.         if(++ageCount[p[i].age] < 101){  
  51.             filter[filter_num++] = i;  
  52.         }  
  53.     }  
  54.     int count;  
  55.     int m,amin,amax;  
  56.     bool flag;  
  57.     int unfilter;  
  58.     for(i=0;i<k;i++){  
  59.         scanf("%d %d %d",&m,&amin,&amax);  
  60.         //cin>>m>>amin>>amax;  
  61.         count = 0;  
  62.         flag = true;  
  63.         printf("Case #%d:\n",i+1);  
  64.         for(j=0;j<filter_num;j++){  
  65.             unfilter = filter[j];  
  66.             if(p[unfilter].age >= amin && p[unfilter].age<= amax){  
  67.                 printf("%s %d %d\n",p[unfilter].name,p[unfilter].age,p[unfilter].worth);  
  68.                 flag = false;  
  69.                 count ++;  
  70.                 if(count >= m){break;}  
  71.             }  
  72.         }  
  73.         if(flag)printf("None\n");  
  74.     }  
  75.     system( "PAUSE");  
  76.     return 0;  
  77. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值