Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the net worths of N people, you must find the M richest people in a given range of their ages.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers: N (≤10​5​​) - the total number of people, and K (≤10​3​​) - the number of queries. Then N lines follow, each contains the name (string of no more than 8 characters without space), age (integer in (0, 200]), and the net worth (integer in [−10​6​​, 10​6​​]) of a person. Finally there are K lines of queries, each contains three positive integers: M (≤ 100) - the maximum number of outputs, and [A​min​​, A​max​​] which are the range of ages. All the numbers in a line are separated by a space.

Output Specification:

For each query, first print in a line Case #X: where X is the query number starting from 1. Then output the M richest people with their ages in the range [A​min​​, A​max​​]. Each person's information occupies a line, in the format Name Age Net_Worth.

The outputs must be in non-increasing order of the net worths. In case there are equal worths, it must be in non-decreasing order of the ages. If both worths and ages are the same, then the output must be in non-decreasing alphabetical order of the names. It is guaranteed that there is no two persons share all the same of the three pieces of information. In case no one is found, output None.

Sample Input:

12 4
Zoe_Bill 35 2333
Bob_Volk 24 5888
Anny_Cin 95 999999
Williams 30 -22
Cindy 76 76000
Alice 18 88888
Joe_Mike 32 3222
Michael 5 300000
Rosemary 40 5888
Dobby 24 5888
Billy 24 5888
Nobody 5 0
4 15 45
4 30 35
4 5 95
1 45 50

Sample Output:

Case #1:
Alice 18 88888
Billy 24 5888
Bob_Volk 24 5888
Dobby 24 5888
Case #2:
Joe_Mike 32 3222
Zoe_Bill 35 2333
Williams 30 -22
Case #3:
Anny_Cin 95 999999
Michael 5 300000
Alice 18 88888
Cindy 76 76000
Case #4:
None
代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct stu
{
char name[];
int age,networth;
}s[];
int cmp(const void *a,const void *b)
{
struct stu *aa = (void *)a,*bb = (void *)b;
if(aa->networth == bb -> networth)
{
if(aa -> age == bb -> age)return strcmp(aa -> name,bb -> name) > ? : -;
return aa -> age > bb -> age ? : -;
}
return aa->networth > bb -> networth ? - : ;
}
int main()
{
int n,k,m,a,b;
scanf("%d%d",&n,&k);
for(int i = ;i < n;i ++)
{
scanf("%s%d%d",s[i].name,&s[i].age,&s[i].networth);
}
qsort(s,n,sizeof(s[]),cmp);
for(int i = ;i <= k;i ++)
{
int c = ;
scanf("%d%d%d",&m,&a,&b);
printf("Case #%d:\n",i);
for(int j = ;j < n;j ++)
{
if(s[j].age >= a && s[j].age <= b)
{
printf("%s %d %d\n",s[j].name,s[j].age,s[j].networth);
c ++;
}
if(c == m)break;
}
if(c == )printf("None\n");
}
}

7-31 The World's Richest(25 分)的更多相关文章

  1. PATA1055 The World's Richest (25 分)

    1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires based ...

  2. PAT 甲级 1055 The World's Richest (25 分)(简单题,要用printf和scanf,否则超时,string 的输入输出要注意)

    1055 The World's Richest (25 分)   Forbes magazine publishes every year its list of billionaires base ...

  3. PAT (Advanced Level) Practice 1055 The World's Richest (25 分) (结构体排序)

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  4. 1055 The World's Richest (25分)(水排序)

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  5. 【PAT甲级】1055 The World's Richest (25 分)

    题意: 输入两个正整数N和K(N<=1e5,K<=1000),接着输入N行,每行包括一位老板的名字,年龄和财富.K次询问,每次输入三个正整数M,L,R(M<=100,L,R<= ...

  6. A1055 The World's Richest(25 分)

    A1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based ...

  7. L2-001 紧急救援 (25 分)

    L2-001 紧急救援 (25 分)   作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快 ...

  8. 1113 Integer Set Partition (25 分)

    1113 Integer Set Partition (25 分) Given a set of N (>1) positive integers, you are supposed to pa ...

  9. PTA 银行排队问题之单队列多窗口服务(25 分)

    银行排队问题之单队列多窗口服务(25 分) 假设银行有K个窗口提供服务,窗口前设一条黄线,所有顾客按到达时间在黄线后排成一条长龙.当有窗口空闲时,下一位顾客即去该窗口处理事务.当有多个窗口可选择时,假 ...

  10. L2-029 特立独行的幸福 (25 分)

    L2-029 特立独行的幸福 (25 分)   对一个十进制数的各位数字做一次平方和,称作一次迭代.如果一个十进制数能通过若干次迭代得到 1,就称该数为幸福数.1 是一个幸福数.此外,例如 19 经过 ...

随机推荐

  1. IP地址与子网掩码的计算

    128.0.0.0=1 192.0.0.0=2224.0.0.0=3 240.0.0.0=4 248.0.0.0=5 252.0.0.0=6 254.0.0.0=7 255.0.0.0=8255.12 ...

  2. 026-B树(一)

    1.内节点:非根非叶子节点,即非根的分支节点. 2.名称:B-树=B树=平衡多路查找树. 3.定义:m阶B树. (0).根节点孩子数rootChildNum范围:若没有孩子节点则孩子数为0,若有孩子则 ...

  3. 20145322 何志威《网络对抗》shellcode注入&Return-to-libc攻击深入

    基础知识 Shellcode实际是一段代码,但却作为数据发送给受攻击服务器,将代码存储到对方的堆栈中,并将堆栈的返回地址利用缓冲区溢出,覆盖成为指向 shellcode的地址. execstack - ...

  4. JQuery实现锚点平滑滚动

    一般使用锚点来跳转到页面指定位置的时候,会生硬地立即跳转到指定位置,但是有些时候我们想要平滑地过渡到指定的位置,那么可以使用JQuery简单的实现这个效果: 比如,这里我们将通过点击<a> ...

  5. Michael-Scott非阻塞队列(lock-free)算法的C实现

    Michael-Scott非阻塞队列算法,即MS-queue算法,是1 9 9 6 年由Maged . M .Michael and M. L. Scott提出的,是最为经典的并发FIFO队列上的算法 ...

  6. POJ 2486 Apple Tree(树形dp)

    http://poj.org/problem?id=2486 题意: 有n个点,每个点有一个权值,从1出发,走k步,最多能获得多少权值.(每个点只能获得一次) 思路: 从1点开始,往下dfs,对于每个 ...

  7. UVa 11538 象棋中的皇后

    https://vjudge.net/problem/UVA-11538 题意: n×m的棋盘,有多少种方法放置两个相互攻击的皇后? 思路: 这两个皇后互相攻击的方式只有3种,在同一行,在同一列,或在 ...

  8. 总结关于express vue-cli

    零零散散,拼起来,花了不少时间,这回把一些东西拼一下吧,免得到时又得重头开始,Blog还没弄好,打算用这些重新写一个,稍接不上,就落后了,这是技术,技术是不断更新换代的,明天这个框架,可以后天就有一个 ...

  9. python 返回系统位数

    # For bit it will and bit it will import struct print()

  10. Redis为什么要把所有数据放到内存中?

    Redis为了达到最快的读写速度将数据都读到内存中,并通过异步的方式将数据写入磁盘.所以Redis具有快速和数据持久化的特性. 如果不将数据放到内存中,磁盘的I/O速度会严重影响redis的性能.在内 ...