Source:

PAT A1062 Talent and Virtue (25 分)

Description:

About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent but with one's virtue outweighs talent can be called a "nobleman(君子)"; being good in neither is a "fool man(愚人)"; yet a fool man is better than a "small man(小人)" who prefers talent than virtue.

Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory.

Input Specification:

Each input file contains one test case. Each case first gives 3 positive integers in a line: N (≤), the total number of people to be ranked; L (≥), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<), the higher line of qualification -- that is, those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages". Those with both grades below H, but with virtue not lower than talent are considered as the "fool men". They are ranked in the same way but after the "noblemen". The rest of people whose grades both pass the Lline are ranked after the "fool men".

Then N lines follow, each gives the information of a person in the format:

ID_Number Virtue_Grade Talent_Grade

where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.

Output Specification:

The first line of output must give M (≤), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID's.

Sample Input:

14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60

Sample Output:

12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90

Keys:

  • 模拟题

Code:

 /*
Data: 2019-07-15 18:19:51
Problem: PAT_A1062#Talent and Virtue
AC: 18:55 题目大意:
圣人:德才 >= H
君子:德 >= H
愚人:德 >= 才
小人:余下者
输入:
第一行给出,人数N<=1e5,及格线L>=60,优秀线H<100
接下来N行,id,virture, talent
输出:
第一行给出,有效人数M
接下来M行,按照圣人,君子,愚人,小人的顺序,按成绩递减输出(德才,德,id)
*/ #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct node
{
int id,mark;
int vir,tal;
}temp;
vector<node> ans; bool cmp(const node &a, const node &b)
{
if(a.mark != b.mark)
return a.mark < b.mark;
else if(a.vir+a.tal != b.vir+b.tal)
return a.vir+a.tal > b.vir+b.tal;
else if(a.vir != b.vir)
return a.vir > b.vir;
else
return a.id < b.id;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,l,h;
scanf("%d%d%d", &n,&l,&h);
for(int i=; i<n; i++)
{
scanf("%d%d%d", &temp.id,&temp.vir,&temp.tal);
if(temp.vir>=l && temp.tal>=l)
{
if(temp.vir>=h && temp.tal>=h)
temp.mark=;
else if(temp.vir>=h)
temp.mark=;
else if(temp.vir>=temp.tal)
temp.mark=;
else
temp.mark=;
ans.push_back(temp);
}
}
sort(ans.begin(),ans.end(),cmp);
printf("%d\n", ans.size());
for(int i=; i<ans.size(); i++)
printf("%08d %d %d\n", ans[i].id,ans[i].vir,ans[i].tal); return ;
}

最新文章

  1. BOOST_AUTO宏
  2. 下载aptana插件jar包
  3. 数组操作splice
  4. IOS客户端Coding项目记录导航
  5. RDLC系列之一 简单示例
  6. ping: unknown host www.baidu.com
  7. 深入理解计算机系统第二版习题解答CSAPP 2.20
  8. 4、Hbase
  9. java虚拟机运行机制
  10. Go学习笔记(一):Ubuntu 环境下Go的安装
  11. 彻底解决TAP(点透)提升移动端点击响应速度
  12. (大数据工程师学习路径)第四步 SQL基础课程----select详解
  13. js 中的 exec( )方法
  14. 网络获取的XML的Pull解析
  15. C++获取基类指针所指子类对象的类名
  16. 浅谈Cookie与Session技术
  17. Unity、C#读取XML
  18. NLP 中的embedding layer
  19. request常用的方法
  20. python初步学习-python函数(一)

热门文章

  1. Dubbo入门到精通学习笔记(二十):MyCat在MySQL主从复制的基础上实现读写分离、MyCat 集群部署(HAProxy + MyCat)、MyCat 高可用负载均衡集群Keepalived
  2. 2.Prometheus安装部署
  3. 【单例模式】懒汉式的线程安全问题 volatile的作用
  4. 数学&amp;计算机工程常用希腊字母表及其发音
  5. java算法汇总(一)
  6. .NET简介
  7. (1.2)学习笔记之mysql体系结构(数据库文件)
  8. mongo import excle
  9. Input标签文件上传,使用详解
  10. python发送微信及企业微信消息