当前位置:网站首页>1062 Talent and Virtue
1062 Talent and Virtue
2022-07-23 20:51:00 【Brosto_ Cloud】
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( saint )"; being less excellent but with one's virtue outweighs talent can be called a "nobleman( gentleman )"; being good in neither is a "fool man( fool )"; yet a fool man is better than a "small man( Villain )" 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 (≤105), 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 considered 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 <algorithm>
#include <string>
using namespace std;
struct Peo {
string id;
int v, t, total;
} a[100010], b[100010], c[100010], d[100010];
int n, l, h, cnt1, cnt2, cnt3, cnt4;
bool cmp(Peo p1, Peo p2) {
return p1.total == p2.total ? (p1.v == p2.v ? (p1.id < p2.id) : p1.v > p2.v) : p1.total > p2.total;
}
int main() {
cin >> n >> l >> h;
string x;
int y, z;
for (int i = 0; i < n; i++) {
cin >> x >> y >> z;
if (y >= l && z >= l) {
if (y >= h && z >= h) {
a[cnt1].id = x;
a[cnt1].v = y;
a[cnt1].t = z;
a[cnt1].total = y + z;
cnt1++;
} else if (z < h && y >= h) {
b[cnt2].id = x;
b[cnt2].v = y;
b[cnt2].t = z;
b[cnt2].total = y + z;
cnt2++;
} else if (y < h && z < h && y >= z) {
c[cnt3].id = x;
c[cnt3].v = y;
c[cnt3].t = z;
c[cnt3].total = y + z;
cnt3++;
} else {
d[cnt4].id = x;
d[cnt4].v = y;
d[cnt4].t = z;
d[cnt4].total = y + z;
cnt4++;
}
}
}
sort(a, a + cnt1, cmp);
sort(b, b + cnt2, cmp);
sort(c, c + cnt3, cmp);
sort(d, d + cnt4, cmp);
cout << cnt1 + cnt2 + cnt3 + cnt4 << endl;
for (int i = 0; i < cnt1; i++) {
cout << a[i].id << ' ' << a[i].v << ' ' << a[i].t << endl;
}
for (int i = 0; i < cnt2; i++) {
cout << b[i].id << ' ' << b[i].v << ' ' << b[i].t << endl;
}
for (int i = 0; i < cnt3; i++) {
cout << c[i].id << ' ' << c[i].v << ' ' << c[i].t << endl;
}
for (int i = 0; i < cnt4; i++) {
cout << d[i].id << ' ' << d[i].v << ' ' << d[i].t << endl;
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
AB team score flow chart, get the names of the players who score three consecutive times and the names of the players who catch up with and surpass the opponents each time (PDD)
大三实习生,字节跳动面经分享,已拿Offer
[PDD interview] analyze the activity of applications (cameras) in mobile phones
-2021最新对比学习(Contrastive Learning)相关必读论文整理分享
Ssm+mysql to realize snack mall system (e-commerce shopping)
【云享读书会第13期】第五章FFmpeg 查看媒体信息和处理音视频文件的常用方法
Read the five flow indicators of R & D efficiency insight
Day 12: continued day 11 (BGP related knowledge)
STM32C8t6 驱动激光雷达实战(二)
视觉slam学习|基础篇01
【Scratch画图100例】图46-scratch绘制花朵 少儿编程 scratch编程画图案例教程 考级比赛画图集训案例
【攻防世界WEB】难度四星12分进阶题:Confusion1
实践数据湖iceberg 第三十七课 kakfa写入iceberg的 icberg表的 enfource ,not enfource测试
一道golang中关于for range常见坑的面试题
第3章业务功能开发(创建线索)
OpenLayers实例-Advanced Mapbox Vector Tiles-高级Mapbox矢量贴图
OOM机制
2022.7.11 MySQL job
Improving Performance with Explicit Rendering(通过显式渲染提高性能)
三层交换机配置MSTP协议详解【华为eNSP实验】









