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 (<=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 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<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct student{char id[10];int vit,tal,sum;int flag;
} stu[100010];bool cmp(student  a,student    b){if(a.flag != b.flag) return a.flag < b.flag;else if(a.sum != b.sum) return a.sum > b.sum;else if(a.vit != b.vit) return a.vit > b.vit;else return strcmp(a.id,b.id) < 0;
}int main(){int n,L,h;scanf("%d%d%d",&n,&L,&h);int m = n;for(int i = 0; i < n; i++){scanf("%s %d %d",stu[i].id,&stu[i].vit,&stu[i].tal);stu[i].sum = stu[i].vit + stu[i].tal;if(stu[i].vit < L || stu[i].tal < L){stu[i].flag = 5;m--;}else if(stu[i].vit >= h && stu[i].tal >= h) stu[i].flag = 1;else if(stu[i].tal < h && stu[i].vit >= h) stu[i].flag = 2;else if(stu[i].vit >= stu[i].tal) stu[i].flag = 3;else stu[i].flag = 4;}sort(stu,stu+n,cmp);printf("%d\n",m);for(int i = 0; i < m; i++){printf("%s %d %d\n",stu[i].id,stu[i].vit,stu[i].tal);}return 0;
}

转载于:https://www.cnblogs.com/wanghao-boke/p/8565703.html

1062. Talent and Virtue (25)相关推荐

  1. 1062 Talent and Virtue (25 分)

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

  2. 1062 Talent and Virtue 25

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

  3. 1062 Talent and Virtue (25 分)(坑点分析)

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

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

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

  5. 1062 Talent and Virtue (25分)

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

  6. 【PAT甲级】1062 Talent and Virtue (25分)

    解题过程的小记录,如有错误欢迎指出. 小导航~ 题目分析 注意点 我的解题过程 思路 bug 代码 dalao的代码 借鉴点 题目分析 对一组人的德才分按照给定的规则进行排序 注意点 弄清楚一共分为四 ...

  7. PAT A1062 Talent and Virtue (25分)

    题意:德才均大于及格线low的才进行排序,排序的人按种姓分为 :) sages-nobleman-fool man-trash 对于人的类型的排序只需要在结构体中加入一个int type即可,通过这个 ...

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

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

  9. PAT 甲级 1062 Talent and Virtue

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

最新文章

  1. Chrome插件(Extensions)开发实践
  2. 【Java】6.1 Java 8增强的包装类
  3. 微信公众号 获得多客服使用权限
  4. 从第一范式(2nf)到第二范式(3nf)_啥是数据库范式
  5. java enum.isdefined_C# System.Enum.IsDefined 方法 - CSharp 参考教程
  6. WebApi实现验证授权Token,WebApi生成文档等
  7. java移位操作示例
  8. 两个PNP三极管组成限流电路原理分析
  9. 制作可被svchost调用的服务(下)
  10. js下载文件格式为Excel后提示与文件扩展名不一致,打开文件前请验证文件没有损坏且来源可信.
  11. MySQL必知必会2
  12. Anaconda安装Unpacking payload step frozen
  13. 智能代还行业怎么样?合法吗?代还APP开发靠谱吗?
  14. U盘用来安装系统后无法打开
  15. 飞桨PaddlePaddle-百度架构师手把手带你零基础实践深度学习——21日学习总结
  16. Linux的obj文件,【IOS开发】linux 下安装object-c环境。。(初期学习的时候用)
  17. Power BI中如何处理相同名称的客户
  18. 提供数据销毁服务 硬盘,磁带,光盘等销毁服务
  19. electron安装教程
  20. [搜片神器]BT种子下载超时很多的问题分析

热门文章

  1. win7下 apache2.2 +php5.4 环境搭建
  2. Javascript之创建对象(原型模式)
  3. css中em与px的介绍及换算方法
  4. jquery ajax 上传文件 demo,Jquery+AJAX上传文件,无刷新上传并重命名文件
  5. java executor spring_Spring+TaskExecutor实例
  6. 7 win 卸载node_node怎么卸载?Windows卸载node方法
  7. redhat linux7.0的安装
  8. 8086除法指令DIV,IDIV
  9. 二叉树中的最大路径和
  10. You have unstaged changes.