7-31 The World's Richest(25 分)
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
(≤105) - the total number of people, and K
(≤103) - 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 [−106, 106]) of a person. Finally there are K
lines of queries, each contains three positive integers: M
(≤ 100) - the maximum number of outputs, and [Amin, Amax] 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 [Amin, Amax]. 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 分)的更多相关文章
- PATA1055 The World's Richest (25 分)
1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires based ...
- 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 ...
- 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 ...
- 1055 The World's Richest (25分)(水排序)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- 【PAT甲级】1055 The World's Richest (25 分)
题意: 输入两个正整数N和K(N<=1e5,K<=1000),接着输入N行,每行包括一位老板的名字,年龄和财富.K次询问,每次输入三个正整数M,L,R(M<=100,L,R<= ...
- A1055 The World's Richest(25 分)
A1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based ...
- L2-001 紧急救援 (25 分)
L2-001 紧急救援 (25 分) 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快 ...
- 1113 Integer Set Partition (25 分)
1113 Integer Set Partition (25 分) Given a set of N (>1) positive integers, you are supposed to pa ...
- PTA 银行排队问题之单队列多窗口服务(25 分)
银行排队问题之单队列多窗口服务(25 分) 假设银行有K个窗口提供服务,窗口前设一条黄线,所有顾客按到达时间在黄线后排成一条长龙.当有窗口空闲时,下一位顾客即去该窗口处理事务.当有多个窗口可选择时,假 ...
- L2-029 特立独行的幸福 (25 分)
L2-029 特立独行的幸福 (25 分) 对一个十进制数的各位数字做一次平方和,称作一次迭代.如果一个十进制数能通过若干次迭代得到 1,就称该数为幸福数.1 是一个幸福数.此外,例如 19 经过 ...
随机推荐
- 关于Oracle误操作--数据被Commit后的数据回退恢复(闪回)
今天操作Oracle数据库时,做一个Update数据时,不小心少写了个where,看这粗心大意的. 于是乎,把所有的员工工号都给更新成一个同一个工号了.这是一个悲催的故事. 因为工号是Check了好多 ...
- SVN提交修改时出现:Checksum mismatch
在使用SVN commit提交修改时,提示Checksum mismatch 问题,提示版本不一致,不能提交,类似于下图. 图片来源于网络,如有侵权,请告知删除. 搜索stackoverflow.co ...
- python实现指定目录下批量文件的单词计数:并发版本
在 文章 <python实现指定目录下批量文件的单词计数:串行版本>中, 总体思路是: A. 一次性获取指定目录下的所有符合条件的文件 -> B. 一次性获取所有文件的所有文件行 - ...
- surface知识点
SurfaceView和TextureView 在学习直播的过程遇到一个问题:连麦场景下能够支持大小窗口切换(即小窗口变大,大窗口变小),大窗口是TextView(用于拉流显示),而小窗口是Surfa ...
- springcloud9----feign-client-without-hystrix
package com.itmuch.cloud; import org.springframework.boot.SpringApplication; import org.springframew ...
- Underscore-逐行分析
标签: // Underscore.js 1.8.3// http://underscorejs.org// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud ...
- P1052 过河(离散化+dp)
P1052 过河 dp不难,重点是要想到离散化. 石子个数$<=100$意味着有大量空间空置,我们可以缩掉这些空间. 实现的话自己yy下就差不多了. #include<iostream&g ...
- vSphere Client开启虚拟机提示:出现了常规系统错误: 由于目标计算机积极拒绝,无法连接。
进入VCenter Server服务器上 进入服务管理器,查看 VMware vCenter workflow manager 是否启动,如未启动,则改为启动,问题得以解决 再次启动虚拟机,已启动!
- java maven 操作 收集的一些命令
maven打包: mvn clean package -Dmaven.test.skip=true 运行jar: java -jar target/spring-boot-scheduler-1.0. ...
- 【Rest】在Dubbo中开发REST风格的远程调用(RESTful Remoting)
目录 概述 REST的优点 应用场景 快速入门 标准Java REST API:JAX-RS简介 REST服务提供端详解 HTTP POST/GET的实现 Annotation放在接口类还是实现类 J ...