Source:

PAT A1055 The World's Richest (25 分)

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 [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

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的更多相关文章

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

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

  2. PAT1055:The World's Richest

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

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

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

  4. A1055. The World's Richest

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. cesium左侧列表定位目标

    cesium左侧列表定位目标 功能:根据左侧列表经纬度等信息的值,进行搜索定位. 列表: 1  点击清除按钮可以清空所有input的值 2  点击查找可以定位到位置,如果输入的值不在范围内,会有弹出框 ...

  2. Vue环境搭建及第一个helloWorld

    Vue环境搭建及第一个helloWorld 一.环境搭建 1.node.js环境安装配置  https://www.cnblogs.com/liuqiyun/p/8133904.html 或者 htt ...

  3. git for windows 2.1版本git bash下git log乱码修复

    git bash,输入以下命令git config --global i18n.logoutputencoding utf-8git config quotepath false关闭git bash, ...

  4. 5、springcloud整合mybatis注解方式

    1.上一篇学习了服务提供者provider,但是并不是单单就学习了服务提供者.中间还穿插使用了Hikari数据源和spring cloud整合mybatis.但是上篇使用mybatis时还是沿用了老的 ...

  5. (转)Unity Cinemachine插件,实现单目标和多目标之间切换

    Unity Cinemachine插件学习笔记,实现单目标和多目标之间切换*版本要求Unity2017.1及以上. 参考资料: [官方] Unity 2017.1正式版发布 Cinemachine插件 ...

  6. Jmeter的安装与环境配置

    1.首先从jmeter的官网http://jmeter.apache.org/download_jmeter.cgi下载jmeter,目前最新版本为5.1,支持的JDK为1.8.. 然后进行解压. 2 ...

  7. element 的时间快捷键

    1. <div> <el-date-picker v-model="value4" type="month" :picker-options= ...

  8. js 实现 间隙滚动效果

    代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...

  9. virtualbox ubuntu 磁盘大小扩容

    前言 虚拟机软件: virtuabox 虚拟机运行的系统: Ubuntu 18.04.3 desktop 如果需要扩容的虚拟机在运行中,请将需要扩容的虚拟机进行关机 方法 先设置虚拟机的虚拟硬盘的大小 ...

  10. Ruby——输入&输出

    Ruby的输入和输出操作.输入是程序从键盘.文件或者其他程序读取数据.输出是程序产生数据.可以输出到屏幕.文件或者其他程序. Ruby中的一些类有些方法会执行输入&输出操作.例如Kernel. ...