PAT甲1055 The World's Richest(25 分)

#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

struct person
{
    char name[10];
    int age;
    int netw;
}p[100010];

int N,K;

bool cmp(person a,person b)
{
    if(a.netw!=b.netw)return a.netw>b.netw;
    else if(a.age!=b.age) return a.age<b.age;
    else return strcmp(a.name,b.name)<0;
}

int main()
{
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++)
    {
        scanf("%s %d %d",&p[i].name,&p[i].age,&p[i].netw);
    }
    sort(p,p+N,cmp);
    int M,Amin,Amax;
    for(int i=1;i<=K;i++)
    {
        scanf("%d%d%d",&M,&Amin,&Amax);
        printf("Case #%d:\n",i);
        int num=0;
        for(int j=0;j<N&&num<M;j++)
        {
            if(p[j].age>=Amin&&p[j].age<=Amax)
            {
                printf("%s %d %d\n",p[j].name,p[j].age,p[j].netw);
                num++;
            }
        }
        if(num==0)
            printf("None\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/yhy489275918/article/details/81878079