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 Hbut 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 L line 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 Mlines 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
 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Node
{
int ID, vir, tal, lab;
}node[];
int N, L, H;
bool cmp(Node a, Node b)
{
if (a.lab != b.lab)
return a.lab < b.lab;
else if ((a.tal + a.vir) != (b.tal + b.vir))
return (a.tal + a.vir) > (b.tal + b.vir);
else if (a.vir!=b.vir)
return a.vir > b.vir;
else
return a.ID < b.ID;
}
int main()
{
cin >> N >> L >> H;
int M = ;
for (int i = ; i < N; ++i)
{
cin >> node[M].ID >> node[M].vir >> node[M].tal;
if (node[M].vir < L || node[M].tal < L)
continue;
else if (node[M].vir >= H && node[M].tal >= H)
node[M].lab = ;
else if (node[M].vir >= H && node[M].tal < H)
node[M].lab = ;
else if (node[M].vir < H && node[M].tal < H && node[M].vir >= node[M].tal)
node[M].lab = ;
else
node[M].lab = ;
M++;
}
cout << M << endl;
sort(node, node + M, cmp);
for (int i = ; i < M; ++i)
cout << node[i].ID << " " << node[i].vir << " " << node[i].tal << endl;
return ;
}

最新文章

  1. Windows on Device 项目实践 3 - 火焰报警器制作
  2. Android获取网络图片
  3. UML2
  4. Java transient关键字序列化时使用小记
  5. 《面向对象程序设计》第二次作业(1)(A+B问题)
  6. BPMN 2.0规范
  7. StringBuffer的替换和反转和截取功能
  8. Oracle多行记录合并的几种方法
  9. Java中常用的字节流和字符流
  10. 【WIN10】移植opencc到WIN10-UWP,實現自己的繁簡轉換工具
  11. javascript基础拾遗(九)
  12. Python3基础 while 斐波那契数列
  13. hive 客户端执行select count(1) from t_sz01
  14. c# 内存泄漏检查心得
  15. 201621123012 《Java程序设计》第14次学习总结
  16. Linux修改服务器ip
  17. hdu1428漫步校园
  18. php中POST与GET区别
  19. Mac下MongoDB enterprise版的安装
  20. python练习七十一:文件操作练习

热门文章

  1. http://ajax.open-open.com/ ajax开源家园
  2. jedis3.1.0在weblogic(jdk1.6)中无法运行
  3. 在任务管理中显示进程ID号
  4. selenium基础(脚本模块化)
  5. 机器学习-一对多(多分类)代码实现(matlab)
  6. UNIX环境高级编程------apue.h找不到
  7. Django问题2
  8. python 简单的图片比较
  9. 以太坊geth客户端下的一些常用命令
  10. Oracle SQL性能优化【转】