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<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct{
char name[];
int age;
int worth;
}info;
bool cmp(info a, info 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) < ;
} info people[];
int main(){
int N, K;
scanf("%d%d", &N, &K);
for(int i = ; i < N; i++){
scanf("%s %d %d", people[i].name, &people[i].age, &people[i].worth);
}
sort(people, people + N, cmp);
for(int i = ; i < K; i++){
int M, min_, max_, cnt = ;
scanf("%d%d%d", &M, &min_, &max_);
printf("Case #%d:\n", i + );
for(int j = ; j < N; j++){
if(people[j].age <= max_ && people[j].age >= min_){
printf("%s %d %d\n", people[j].name, people[j].age, people[j].worth);
cnt++;
}
if(cnt == M){
break;
}
}
if(cnt == )
printf("None\n");
}
cin >> K;
return ;
}

A1055. The World's Richest的更多相关文章

  1. A1055 The World's Richest(25 分)

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

  2. PAT A1055 The World's Richest (25 分)——排序

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  3. PAT甲级——A1055 The World's Richest

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  4. PAT_A1055#The World's Richest

    Source: PAT A1055 The World's Richest (25 分) Description: Forbes magazine publishes every year its l ...

  5. 1055. The World's Richest (25)

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  6. PAT1055:The World's Richest

    1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  7. PAT 1055 The World's Richest[排序][如何不超时]

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

  8. 7-31 The World's Richest(25 分)

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  9. pat1055. The World's Richest (25)

    1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

随机推荐

  1. RabbitMQ --- Hello Mr.Tua

    目录 RabbitMQ --- Work Queues(工作队列) RabbitMQ --- Publish/Subscribe(发布/订阅) RabbitMQ --- Routing(路由) 安装环 ...

  2. 阿里云centos内docker的搭建

    由于docker在17之后的版本分成了docker EE(企业版)和docker CE(社区版),那么我们在安装的时候就要开始纠结的选择了,这里我推荐了docker CE(社区版). 实际上这两个版本 ...

  3. 开启C语言的学习之门

    本人是一枚工业界的码农,为了职业道路越来越宽广决定向上位机方面进军,C语言曾经在大学里面学过点皮毛但是离应用远远不够,尽量每天在工作之余更新自己学习的进度,同时也希望有大神能给予在编程道路上的指导,话 ...

  4. SpringBoot笔记

    官网: http://springboot.fun/ 收集到一个比较全的: https://blog.csdn.net/xiaoyu411502/article/details/52474037 Id ...

  5. Linux第五周学习总结

    作者:黎静 一.知识点总结 (一)给MenuOS增加time和time-asm命令 1.更新menu代码到最新版 2.test.c中main函数里,增加MenuConfig() 3.增加对应的两个函数 ...

  6. 关于QQ的NABCD模型

    组名:思甜雅 关于QQ的NABCD模型 N--Need 随着电脑的普及,人们需要在网络上进行交流,现有的交流工具不够完善,不能够全部满足人们对于交流沟通中的需要. 初步了解人们的需求,人们需要一款可以 ...

  7. PHP文件下载功能实现

    客户端的浏览器通过HTTP协议可以实现文件下载: 方法一: 能提供用户下载的最简单的方法就是使用一个<a></a>标签,比如在页面中添加这么一行代码 <a href=&q ...

  8. OSI的七层模型介绍

    应用层: 文件传输,电子邮件,文件服务,虚拟终端 TFTP,HTTP,SNMP,FTP,SMTP,DNS,Telnet 表示层: 数据格式化,代码转换,数据加密 没有协议. (信息的语法语义以及它们的 ...

  9. 开发一个微信小程序实例教程

    一.注册小程序账号 1.进入微信公众平台(https://mp.weixin.qq.com/),注册小程序账号,根据提示填写对应的信息即可.2.注册成功后进入首页,在 小程序发布流程->小程序开 ...

  10. BZOJ4652 NOI2016循环之美(莫比乌斯反演+杜教筛)

    因为要求数值不同,不妨设gcd(x,y)=1.由提示可以知道,x/y是纯循环小数的充要条件是x·klen=x(mod y).因为x和y互质,两边同除x,得klen=1(mod y).那么当且仅当k和y ...