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 (≤10​5​​ ), the total number of people to be ranked; L (≥60), 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 (<100), 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 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 (≤N), 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

思路

好像就是乙级里的德才那题,还是用的笨办法,四种人四个分组,然后每组分别进行排序,可能做麻烦了

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
struct man
{string id;int virtue;int talent;int total;
};
bool cmp(man a, man b)
{if (a.total != b.total)return a.total > b.total;else if (a.virtue != b.virtue)return a.virtue > b.virtue;elsereturn a.id < b.id;
}
int main()
{int n, l, h;cin >> n >> l >> h;vector<man> sage;vector<man> noble;vector<man> fool;vector<man> small;for (int i = 0; i < n; i++){man s;cin >> s.id >> s.virtue >> s.talent;s.total = s.talent + s.virtue;if (s.virtue >= l && s.talent >= l){if (s.talent >= h && s.virtue >= h)sage.push_back(s);else if (s.talent < h && s.virtue >= h)noble.push_back(s);else if (s.talent < h && s.virtue < h && s.virtue >= s.talent)fool.push_back(s);elsesmall.push_back(s);}}sort(sage.begin(), sage.end(), cmp);sort(noble.begin(), noble.end(), cmp);sort(fool.begin(), fool.end(), cmp);sort(small.begin(), small.end(), cmp);int all = sage.size() + noble.size() + fool.size() + small.size();cout << all << endl;for (int i = 0; i < sage.size(); i++) cout << sage[i].id << ' ' << sage[i].virtue << ' ' << sage[i].talent << endl;for (int i = 0; i < noble.size(); i++) cout << noble[i].id << ' ' << noble[i].virtue << ' ' << noble[i].talent << endl;for (int i = 0; i < fool.size(); i++) cout << fool[i].id << ' ' << fool[i].virtue << ' ' << fool[i].talent << endl;for (int i = 0; i < small.size(); i++) cout << small[i].id << ' ' << small[i].virtue << ' ' << small[i].talent << endl;system("pause");return 0;
}

PAT甲级1062 Talent and Virtue相关推荐

  1. PAT甲级1062 Talent and Virtue:[C++题解]结构体、哈希表

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 分4个vector,单独排序即可. ac代码 #include<bits/stdc++.h> using namespa ...

  2. PAT 甲级 1062 Talent and Virtue

    1062 Talent and Virtue 题目大意:给出一组人数,按照要求分类再排序输出.圣人是virtue和talent都超过h的人,君子是virtue超过h并且talent位于[l,h)区间内 ...

  3. 1062 Talent and Virtue (25 分)

    1062 Talent and Virtue (25 分) 题意 先给出三个数N(成员人数),L(及格线),H(优秀线) 给出一组成员信息,包括id,品德,才能,给这组成员排序. 当该成员品德和才能都 ...

  4. 1062 Talent and Virtue 25

    1062 Talent and Virtue 25 题目链接:A1062 Talent and Virtue 25 问题思路 我尝试了两种思路: 根据每个人的分数确定其是哪个级别(rank)的人,以总 ...

  5. 1062. Talent and Virtue (25)-PAT甲级真题

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

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

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

  7. 1062. Talent and Virtue (25)

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

  8. 1062 Talent and Virtue(排序)

    这类题目归结于常用技巧与算法,有很鲜明的套路,重在理解其规则,通常写起来不算太复杂. 题目描述: 题目大致意思: 输入N和最低下限和最高上限,接着输入N个人的编号,美德和天赋.如果美德和天赋都不低于最 ...

  9. 1062 Talent and Virtue (25分)

    题目地址 About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked a ...

最新文章

  1. Python 进阶之路 (九) 再立Flag, 社区最全的itertools深度解析(上)
  2. 列举ospf的5种报文类型_这5种“专升本”你都知道吗?那个含金量更高呢?报考如何选择?...
  3. 蓝桥杯 试题 基础练习 芯片测试——12行代码AC
  4. django图片上传到oss_从攻防角度看oss安全(二)
  5. django1.6 mysql_如何在Django1.6结合Python3.4版本中使用MySql
  6. 中国教育行业市场行情动态及投资潜力研究报告(2022-2028年)
  7. SitePoint / Flippa Hack Day:入侵我们的第一个物联网项目
  8. TYPHOON cms漏洞 简书(ssh篇)
  9. 文曲星猜数字用c语言编程,文曲星中的猜数字游戏,要猜一个四位数,有什么通用公式?...
  10. Linux命令卸载谷歌浏览器,UBUNTU16.04安装谷歌浏览器卸载firefox浏览器
  11. debain系统安装nginx
  12. Qt 样式表之QSS
  13. linux 中 lrwxrwxrwx是什么意思?
  14. PHPStorm 显示自动换行
  15. 1984年高考数学试题。
  16. 基于ubuntu系统下的USB设备绑定
  17. 图像卷积及其Python实现
  18. Kubernetes API Aggregated 是什么
  19. 程序员最怕的四个字:通宵发布!
  20. 获取固有节假日的时间戳数组 (美国节假日)

热门文章

  1. HBuilder X问题记录
  2. vi打开服务器上的文件,虚拟机vi编辑器怎么打开
  3. 股票自动委托下单html,股票怎么设置自动挂单?股票挂单的方式
  4. 解决GitHub频繁要求verify email的问题
  5. c语言 生化危机游戏,生化危机6佣兵全人物+服装解锁
  6. 区块链三加一 “成才”路上提个醒:区块链培训机构鱼龙混杂
  7. VIVADO报错:[opt31-67]之MIG ip核综合失败
  8. 武田完成收购夏尔,成为以价值观为基础的研发驱动型跨国生物制药翘楚
  9. 瞬间的牵手,留下了永恒的怀念!
  10. MLCS algorithm