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 ;
}

PAT甲级——A1062 Talent and Virtue的更多相关文章

  1. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  2. PAT_A1062#Talent and Virtue

    Source: PAT A1062 Talent and Virtue (25 分) Description: About 900 years ago, a Chinese philosopher S ...

  3. 【算法学习记录-排序题】【PAT A1062】Talent and Virtue

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  4. PAT 1062 Talent and Virtue[难]

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  5. PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)

    1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vecto ...

  6. PAT 1062 Talent and Virtue

    #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #i ...

  7. 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise

    题目信息 1062. Talent and Virtue (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B About 900 years ago, a Chine ...

  8. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  9. 【转载】【PAT】PAT甲级题型分类整理

    最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...

随机推荐

  1. day 56 Django基础五之django模型层(二)多表操作

    Django基础五之django模型层(二)多表操作   本节目录 一 创建模型 二 添加表记录 三 基于对象的跨表查询 四 基于双下划线的跨表查询 五 聚合查询.分组查询.F查询和Q查询 六 ORM ...

  2. import socket模块

    编写两个小脚本实现聊天功能0.1: 脚本一,服务器端:server.py import socket # 调用模块 sk = socket.socket() # 创建socket addess = ( ...

  3. 牛客集训第七场J /// DP

    题目大意: 在矩阵(只有52种字符)中找出所有不包含重复字符的子矩阵个数 #include <bits/stdc++.h> #define ll long long using names ...

  4. USACO 2013 January Silver Painting the Fence /// oj23695

    题目大意: 输入n,k :n次操作 找到覆盖次数在k及以上的段的总长 一开始位置在0 左右活动范围为1-1000000000 接下来n行描述每次操作的步数和方向 Sample Input 6 22 R ...

  5. AbstractByteBuf 源码分析

    主要成员变量 static final ResourceLeakDetector<ByteBuf> leakDetector = new ResourceLeakDetector<B ...

  6. scull 中的设备注册

    在内部, scull 使用一个 struct scull_dev 类型的结构表示每个设备. 这个结构定义为: struct scull_dev { struct scull_qset *data;  ...

  7. 【默默努力】vue-pc-app

    最近在github上面看到了一个团队的项目,真的非常赞.他们进行vue-cli的二次开发,将项目用自己的方式打包. 今天的这个开源项目地址为:https://github.com/tffe-team/ ...

  8. mysql 表查询结果 总行数计算

    一般的查询语句是这样的 SELECT  id,name FROM SystemEvents WHERE  1=1 limit 9,10 SELECT  * FROM SystemEvents WHER ...

  9. IDEA将代码推送至远程GitHub仓库

    1 在项目根路径下添加.gitignore文件 2 创建本地git仓库 3 git add操作 快捷键 ctrl+alt+a 4 git commit操作 快捷键ctrl+k 5 git push操作 ...

  10. Spring_数据校验和自定义检验规则和分组校验

    @Validated  :绑定需要校验的数据. 数据校验规则:为数据绑定校验的规则 private Long booId;@NotNull(message = "不能为空")pri ...