zoukankan      html  css  js  c++  java
  • PAT:1055. The World's Richest (25) AC

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    struct Person
    {
      char name[10];
      int age,money;
    }P[100010];
    bool cmp(Person a,Person b)
    {
      if(a.money!=b.money)
        return a.money>b.money;
      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);
      for(int i=0 ; i<N ; ++i)
      {
        scanf("%s %d %d",&P[i].name, &P[i].age, &P[i].money);
      }
      sort(P,P+N,cmp);
    
      for(int t=1 ; t<=K ; ++t)      //查询K次
      {
        int cnt=0,Qpeople,Qyoung,Qold;  //输出记录cnt,输出查询最大人数,最低年龄,最高年龄
        scanf("%d%d%d",&Qpeople, &Qyoung, &Qold);
        printf("Case #%d:
    ",t);
        for(int i=0 ; i<N ; ++i)
        {
          if(cnt==Qpeople){      //输出已足够
            break;
          }
          if(P[i].age>=Qyoung && P[i].age<=Qold)
          {
            printf("%s %d %d
    ",P[i].name, P[i].age, P[i].money);
            ++cnt;
          }
        }
        if(0==cnt){
          printf("None
    ");
        }
      }
      return 0;
    }
  • 相关阅读:
    sqlsever中生成GUID的方法
    部署项目到服务器
    读后感
    第二次作业
    课堂作业
    第一次作业 开发环境配置介绍
    第二次结对作业
    代码审查
    最大连续子数组和
    单元测试
  • 原文地址:https://www.cnblogs.com/Evence/p/4307738.html
Copyright © 2011-2022 走看看