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. php \r \n 和 <br/> \t

    利用\r \n 和 <br/> \t做了个实验,话不多说,看代码就很清楚的知道

  2. ng-深度学习-课程笔记-17: 序列模型和注意力机制(Week3)

    1 基础模型(Basic models) 一个机器翻译的例子,比如把法语翻译成英语,如何构建一个神经网络来解决这个问题呢? 首先用RNN构建一个encoder,对法语进行编码,得到一系列特征 然后用R ...

  3. Java学习笔记之MyEclipse 2017 CI 7、CI 8、CI 9和CI 10的安装与激活

    0x00 前言 本文介绍MyEclipse 2017 CI 7.CI 8.CI 9和CI 10的安装与激活. 重要提示:此方法理论上应该能激活MyEclipse 2017 CI所有系列,即激活方法是通 ...

  4. SQL学习笔记六之MySQL数据备份和pymysql模块

    mysql六:数据备份.pymysql模块   阅读目录 一 IDE工具介绍 二 MySQL数据备份 三 pymysql模块 一 IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测 ...

  5. linux内核分析第五周-分析system_call中断处理过程

    本实验目的:通过以一个简单的menu小程序,跟踪系统调用的过程,分析与总结系统调用的机制和三层进入的过程. 实验原理:系统调用处理过程与中断处理的机制 系统调用是通过软中断指令 INT 0x80 实现 ...

  6. 205315Java实验二实验报告

    实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步骤 (一)单元测试 用程序解决问题时,要会写三种码: ...

  7. 从0开始学习 GITHUB 系列之「GITHUB 常见的几种操作」【转】

    本文转载自:http://stormzhang.com/github/2016/09/21/learn-github-from-zero8/ 版权声明:本文为 stormzhang 原创文章,可以随意 ...

  8. tomcat跟目录下work文件夹的作用

    work目录只是tomcat的工作目录,也就是tomcat把jsp转换为class文件的工作目录. jsp,tomcat的工作原理:当浏览器访问某个jsp页面时,tomcat会在work目录里把这个j ...

  9. CycleGAN 配置及其实现

    目录 pytorch-CycleGAN-and-pix2pix 环境要求 安装 Train 用已有数据集训练 Test 预训练模型 训练与测试自己的数据集 遇到的问题 Reference pytorc ...

  10. ros 杀掉所有节点

    rosnode kill -a 或者 rosnode kill --all