PAT_A1055#The World's Richest
Source:
Description:
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 (≤) - the total number of people, and K (≤) - 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 [−]) of a person. Finally there are K lines of queries, each contains three positive integers: M (≤) - 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:
whereX
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 formatName 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
Keys:
- 模拟题
Attention:
- 用string的I/O会超时,换字符数组就好了
Code:
/*
Data: 2019-07-15 18:45:09
Problem: PAT_A1055#The World's Richest
AC: 21:45 题目大意:
排序
输入:
第一行给出,人数N<=1e5,查询数K<=1e3
接下来N行,name,age,worth
接下来K行,入选人数,最小年龄,最大年龄
输出:
按照worth递减,age递增,name递增
*/ #include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
char name[];
int age,worth;
}temp;
vector<node> info; bool cmp(const node &a, const node &b)
{
if(a.worth != b.worth)
return a.worth > b.worth;
else if(a.age != b.age)
return a.age < b.age;
else
return strcmp(a.name,b.name)<;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,m,l,r;
scanf("%d %d", &n,&m);
for(int i=; i<n; i++)
{
scanf("%s %d %d\n", temp.name,&temp.age,&temp.worth);
info.push_back(temp);
}
sort(info.begin(),info.end(),cmp);
for(int i=; i<=m; i++)
{
scanf("%d%d%d", &n,&l,&r);
printf("Case #%d:\n", i);
vector<node> ans;
for(int j=; j<info.size(); j++)
{
if(info[j].age>=l && info[j].age<=r)
ans.push_back(info[j]);
if(ans.size()==n) break;
}
if(ans.size() == ) printf("None\n");
for(int j=; j<ans.size(); j++)
printf("%s %d %d\n", ans[j].name,ans[j].age,ans[j].worth);
} return ;
}
PAT_A1055#The World's Richest的更多相关文章
- 1055. The World's Richest (25)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT1055:The World's Richest
1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT A1055 The World's Richest (25 分)——排序
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- A1055. The World's Richest
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT 1055 The World's Richest[排序][如何不超时]
1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based o ...
- 7-31 The World's Richest(25 分)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- pat1055. The World's Richest (25)
1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- A1055 The World's Richest(25 分)
A1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based ...
- PATA1055 The World's Richest (25 分)
1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires based ...
随机推荐
- python 比较俩个列表中的元素是否相同
如果元素都是数字: # a = [121, 144, 19, 161, 19, 144, 19, 11]# b = [121, 14641, 20736, 361, 25921, 361, 20736 ...
- 个人笔记 - C++相关收藏
一.文件操作 1.C++从txt文件中读取二维的数组
- 框架-.Net:.NET框架
ylbtech-框架-.Net:.NET框架 .NET框架(.NET Framework) 是由微软开发,一个致力于敏捷软件开发(Agile softwaredevelopment).快速应用开发(R ...
- 2.3 Nginx服务的启停控制
在Linux平台下,控制Nginx服务的启停有多种方法 2.3.1 Nginx服务的信号控制 在Nginx服务的启停办法中,有一类是通过信号机制来实现的,Nginx服务器的信号控制如下: Nginx服 ...
- MySql常见的错误
一些MySql运行中遇到的错误总结,大家也可以留言进行我进行汇总. 一.Unknown error 1146 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxEr ...
- springboot整合jsp 遇到的问题
1,在idea中新建jsp文件 首先需要在springboot项目 在src 中webapp /WEB-INF/JSP 当我右键想新建一个jsp文件时默认没有 File->Project Str ...
- 《代码大全2》读书笔记 Week9
本周阅读了<代码大全2>第14章至第17章,这几章对我们熟悉的直线型代码.条件语句.循环语句和一些不常用的控制结构(如goto.try-catch结构)提出了一些使用建议,以下分享条件语句 ...
- 【记录】API Gateway作用? 与过滤器的区别?Nginx与Zuul区别?
网关(gateway)的作用: 网关可以拦截客户端所有请求,对该请求进行权限控制.负载均衡.日志管理.接口调用监控等 过滤器与网关的区别是什么? 过滤器是拦截单个tomcat服务器请求. 网关是拦截整 ...
- teb教程3
配置和运行机器人导航 简介:配置teb_local_planner作为navigation中local planner的插件 参考teb安装 由于局部代价地图的大小和分辨率对优化性能影响很大,因为占据 ...
- 视频专家之路【三】:Vs开发环境的搭建
本文是听了雷宵骅大神的课之后的总结,部分内容借用了其PPT的内容,如有侵权请告知删除. 雷宵骅大神的博客为:https://blog.csdn.net/leixiaohua1020 这里提及一点,原来 ...