PAT 1055. The World's Richest

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1055

题解:

枚举查找符合条件的输出即可。

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 0x6fffffff
struct person
{
    char name[10];//姓名
    int age;//年龄
    int netWorth;//净资产
}richer[100005];
int q[100005];
int ageRank[205];
bool cmp(const struct person &a,const struct person &b)
{//按 净资产 年龄 姓名 排序
    if(a.netWorth!=b.netWorth)
        return a.netWorth>b.netWorth;
    else if(a.age!=b.age)
        return a.age<b.age;
    else
        return strcmp(a.name,b.name)<0;
}
int main()
{
    int n,m,k,aMin,aMax;
    int idx=0,num,age;
    memset(ageRank,0,sizeof(ageRank));
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i)
        scanf("%s%d%d",richer[i].name,&richer[i].age,&richer[i].netWorth);
    sort(richer,richer+n,cmp);
    for(int i=0;i<n;++i)
    {
        ++ageRank[richer[i].age];
        if(ageRank[richer[i].age]<101)//去除年龄大于100的
            q[idx++]=i;
    }
    for(int i=1;i<=k;++i)
    {
        scanf("%d%d%d",&m,&aMin,&aMax);
        printf("Case #%d:\n",i);
        num=0;
        for(int j=0;j<idx&&num<m;++j)
        {
            age=richer[q[j]].age;
            if(aMin<=age&&age<=aMax)
            {
                printf("%s %d %d\n",richer[q[j]].name,richer[q[j]].age,richer[q[j]].netWorth);
                ++num;
            }
        }
        if(num==0)
            printf("None\n");

    }
    return 0;
}

来源: http://blog.csdn.net/acm_ted/article/details/20659201


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值