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:whereXis 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自动化之函数封装
函数最重要的目的是方便我们重复使用相同的一段程序. 将一些操作隶属于一个函数,以后你想实现相同的操作的时候,只用调用函数名就可以,而不需要重复敲所有的语句. 前面一些记录了selenium的各种API ...
- HTML5: HTML5 介绍
ylbtech-HTML5: HTML5 介绍 1. 什么是 HTML5?返回顶部 HTML5 是下一代 HTML 标准. HTML,HTML 4.01的上一个版本诞生于1999年.自从那儿以后, ...
- 初步认识AutoMapper转载 https://www.cnblogs.com/fred-bao/p/5700776.html
初步认识AutoMapper AutoMapper 初步认识AutoMapper 前言 手动映射 使用AutoMapper 创建映射 Conventions 映射到一个已存在的实例对象 前言 通常 ...
- java 并发——synchronized
java 并发--synchronized 介绍 在平常我们开发的过程中可能会遇到线程安全性的问题,为了保证线程之间操作数据的正确性,我们第一想到的可能就是使用 synchronized 并且 syn ...
- java.lang
package cn.sxt; import java.lang.*; public class BooleanDemo { public static void main(Stri ...
- SpringBoot集成Thymeleaf模板
1.添加起步依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId& ...
- Python面试题之“猴子补丁”(monkey patching)指的是什么?这种做法好吗?
“猴子补丁”就是指,在函数或对象已经定义之后,再去改变它们的行为. 举个例子: import datetime datetime.datetime.now = lambda: datetime.dat ...
- 从Airbnb的发展历程和网易云的大起大落看IT行业创新(第5周课后作业)
我想先根据个人看法回答“创新是什么?”这个空泛的问题.创新是面对当下的资源条件限制创造出能够满足动态需求或解决动态发展中的问题的新策略.这种实用化定义在大部分邻域都勉强能让定义者自圆其说,对于IT行业 ...
- C++ 空类,默认产生哪些成员函数
C++ 空类,默认产生哪些成员函数. 默认构造函数.默认拷贝构造函数.默认析构函数.默认赋值运算符 这四个是我们通常大都知道的.但是除了这四个,还有两个,那就是取址运算符和 取址运算符 con ...
- Linux part2(系统的相关设置变更)
修改Linux的系统语言 首先查看当前系统的语言 1.echo $LANG 查看当前操作系统的语言 中文:zh_CN.UTF-8 英文: en_US.UTF-8 2.临时更改默认语言,当前立即生效 重 ...