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 [AminAmax] 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 [AminAmax]. 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 分)——排序的更多相关文章

  1. 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 ...

  2. PATA1055 The World's Richest (25 分)

    1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires based ...

  3. PAT乙级:1090危险品装箱(25分)

    PAT乙级:1090危险品装箱(25分) 题干 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清 ...

  4. PAT乙级:1070 结绳 (25分)

    PAT乙级:1070 结绳 (25分) 题干 给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟 ...

  5. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  6. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  7. PAT 乙级 1065 单身狗 (25 分)

    1065 单身狗 (25 分) “单身狗”是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数 N(≤ 50 000),是 ...

  8. 【PAT】B1070 结绳(25 分)

    此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...

  9. PAT甲级——1130 Infix Expression (25 分)

    1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...

  10. pat 1149 Dangerous Goods Packaging(25 分)

    1149 Dangerous Goods Packaging(25 分) When shipping goods with containers, we have to be careful not ...

随机推荐

  1. C#基础(202)--类定义,字段与属性,自动属性,方法及常见错误

    c#类的定义规范 字段与属性的比较: 字段: 字段主要是为类的内部做数据交换交互使用,字段一般是private 字段可以赋值,也可以取值 当字段需要为外部数据提供数据的时候,请将字段封装为属性,而不是 ...

  2. Android 底部导航栏实现一 Fragment-replace

    [效果](这里下载的软件收费的试用有水印) [推荐]这里推荐一个图标网http://iconfont.cn/.以上图标来自此图标网 [项目结构] [步骤] ①创建布局文件,写底部导航栏 <?xm ...

  3. Android IPC机制(二)用Messenger进行进程间通信

    Messenger可以在不同进程中传递Message对象,我们在Message中加入我们想要传的数据就可以在进程间的进行数据传递了.Messenger是一种轻量级的IPC方案并对AIDL 进行了封装, ...

  4. java基础(一)---数据类型&Math方法&强制转换

    数据类型及各种Math类方法 public class HelloWorld { public static void main(String args[]) { //各种数据类型的熟悉掌握,强制类型 ...

  5. WiFi的名词缩写

    http://blog.csdn.net/jayxujia123/article/details/12842295 无线网络最初采用的安全机制是WEP(有线等效私密),但是后来发现WEP是很不安全的, ...

  6. (网页)html5 canvas清空画布方法(转)

    总结以下三种清空canvas画布的方式: 1. 最简单的方法:由于canvas每当高度或宽度被重设时,画布内容就会被清空,因此可以用以下方法清空: function clearCanvas() { v ...

  7. [20190322]测试相同语句遇到导致cursor pin S的疑问.txt

    [20190322]测试相同语句遇到导致cursor pin S的疑问.txt--//昨天测试遇到的情况,链接:http://blog.itpub.net/267265/viewspace-26388 ...

  8. mysql 数据库 命令行的操作——对表和字段的操作

    一.对表的操作 1.查看所有表 show tables: 2.创建表 create table 表名(字段1 类型1 约束1 ,字段2 类型2 约束2): 3.修改表的名字 rename table ...

  9. RHEL/Centos7 安装图形化桌面

    Linux是一个多任务的多用户的操作系统,好多linux爱好者在安装完linux后经常遇到一个问题——没有图形化桌面.今天小编在安装RHEL7的时候,一步留神没有安装图形化桌面,下面分享一下安装图形化 ...

  10. shell重定向介绍及使用

    我们在写脚本或用脚本时,往往会发现 > /dev/null 2>&1 这类的命令.之前都是简单的了解一下,并没有深度消化,直到自己写脚本时,不认真写成了2>&1 &g ...