PAT A1055 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 <vector>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
const int maxn = ;
struct node{
string name;
int age,worth;
}nodes[maxn];
bool cmp(const node &a,const node &b){
return a.worth==b.worth?(a.age==b.age?a.name<b.name:a.age<b.age):a.worth>b.worth;
}
int main(){
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<n;i++){
cin>>nodes[i].name>>nodes[i].age>>nodes[i].worth;
}
sort(nodes,nodes+n,cmp);
for(int i=;i<=m;i++){
printf("Case #%d:\n",i);
vector<node> v;
int k,amin,amax;
int nk=;
scanf("%d %d %d",&k,&amin,&amax);
for(int j=;j<n&&nk<k;j++){
if(nodes[j].age<=amax && nodes[j].age>=amin){
nk++;
printf("%s %d %d\n",nodes[j].name.c_str(),nodes[j].age,nodes[j].worth);
}
}
if(nk==)printf("None\n");
}
}
注意点:挺普通的排序题,给的条件也很宽,不会超时
PAT A1055 The World's Richest (25 分)——排序的更多相关文章
- 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 ...
- PATA1055 The World's Richest (25 分)
1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires based ...
- PAT乙级:1090危险品装箱(25分)
PAT乙级:1090危险品装箱(25分) 题干 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清 ...
- PAT乙级:1070 结绳 (25分)
PAT乙级:1070 结绳 (25分) 题干 给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟 ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT 乙级 1065 单身狗 (25 分)
1065 单身狗 (25 分) “单身狗”是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数 N(≤ 50 000),是 ...
- 【PAT】B1070 结绳(25 分)
此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...
- PAT甲级——1130 Infix Expression (25 分)
1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...
- pat 1149 Dangerous Goods Packaging(25 分)
1149 Dangerous Goods Packaging(25 分) When shipping goods with containers, we have to be careful not ...
随机推荐
- 关于数据分析的4点心得:维度、指标、KPI
1.看数据看维度 在对某一项业务或者业务的某个模块进行分析时,可以从大小两个角度去切入分析. 首先站在广阔的视角去看待一些数据.比如对某个产品(消费品),就要分析在大环境下是一个什么样的数据,如市场排 ...
- java方法中,传参是传值还是传址问题(对比C语言、C#和C++)
问题引出: 编写一个简单的交换值的小程序,如果我们只是简单地定义一个交换函数接收两个数,在函数内部定义一个中间变量完成交换.那么当我们把a,b两个实参传给这个函数时,往往得不到预期的结果.这是为什么呢 ...
- vue的diff算法
前言 我的目标是写一个非常详细的关于diff的干货,所以本文有点长.也会用到大量的图片以及代码举例,目的让看这篇文章的朋友一定弄明白diff的边边角角. 先来了解几个点... 1. 当数据发生变化时, ...
- Electron开发笔记—electron-builder打包流程
该文章说明基于win平台下,mac及linux没有实验 关于electron-builder打包可以有两种方案: 1. 打包成文件夹及绿色免安装: electron-builder --dir(依赖w ...
- python LeetCode 两数相除
近一个月一直在写业务,空闲时间刷刷leetcode,刷题过程中遇到了一道比较有意思的题目,和大家分享. 题目描述: 给定两个整数,被除数 dividend 和除数 divisor.将两数相除,要求不使 ...
- Linux Xshell连接Linux服务器时报错Socket error Event: 32 Error: 10053
问题描述 在用Xshell连接Linux服务器时,出现错误提示"Socket error Event: 32 Error: 10053. Connection closing...Socke ...
- springmvc复习笔记----springmvc姓名年龄例子:RequestParam 试水
继续 继上节http://www.cnblogs.com/tk55/p/6652394.html 重要部分颜色突出 结构 包 web.xml 乱码处理方面设置 <url-pattern>* ...
- 决策树ID3算法的java实现(基本适用所有的ID3)
已知:流感训练数据集,预定义两个类别: 求:用ID3算法建立流感的属性描述决策树 流感训练数据集 No. 头痛 肌肉痛 体温 患流感 1 是(1) 是(1) 正常(0) 否(0) 2 是(1) 是(1 ...
- mssql sqlserver 获取指定日期为本月第几个工作日
转自:http://www.maomao365.com/?p=6771 摘要: 下文讲述工作中,需要获取指定日期在当月的工作日 下文讲述常规的指定工作日所在月的天数分析,实现思路:1 生成一个国家法定 ...
- web前端(3)—— html标签及web页面结构
本节内容简单介绍下html都有哪些标签 还是百度首页,查看源代码看看: 我把源代码复制下来另存为html文件里: 注意:网页文件的后缀都是html或者htm 我这用的pycharm编辑器(Python ...