pat1062. Talent and Virtue (25)
1062. Talent and Virtue (25)
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<stack>
#include<cstring>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
struct record{
char id[];
int VG,TG,r;
record(){
r=;
}
};
bool cmp(record a,record b){
if(a.r==b.r){
if(a.VG+a.TG==b.VG+b.TG){
if(a.VG==b.VG){
return strcmp(a.id,b.id)<;
}
return a.VG>b.VG;
}
return a.VG+a.TG>b.VG+b.TG;
}
return a.r>b.r;
}
//Virtue_Grade Talent_Grade
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,l,h;
scanf("%d %d %d",&n,&l,&h);
record *per=new record[n+];
int i,count=,VG,TG,r=;
char id[];
for(i=;i<n;i++){
scanf("%s %d %d",&id,&VG,&TG);
if(VG>=l&&TG>=l){//有可能
if(VG>=h&&TG>=h){
per[count].r+=;
}
else if(VG>=h&&TG<h){//nobleman
per[count].r+=;
}
else if(VG<h&&TG<h&&VG>=TG){//fool man
per[count].r+=;
}
strcpy(per[count].id,id);
per[count].VG=VG;
per[count].TG=TG;
count++;
}
}
sort(per,per+count,cmp);
printf("%d\n",count);
for(i=;i<count;i++){
printf("%s %d %d\n",per[i].id,per[i].VG,per[i].TG);
}
return ;
}
pat1062. Talent and Virtue (25)的更多相关文章
- 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 ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- 1062 Talent and Virtue (25分)(水)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
- pat 1062. Talent and Virtue (25)
难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...
- PAT (Advanced Level) 1062. Talent and Virtue (25)
简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...
- PAT甲题题解-1062. Talent and Virtue (25)-排序水题
水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- 【PAT甲级】1062 Talent and Virtue (25 分)
题意: 输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线.接着输入N行数据,每行包括一个人的ID,道德数值和才能数值.一 ...
- PAT_A1062#Talent and Virtue
Source: PAT A1062 Talent and Virtue (25 分) Description: About 900 years ago, a Chinese philosopher S ...
随机推荐
- Java中是构造器创建对象吗?
首先,这里说明” Java中是构造器创建对象 “这句话是完全错误的. Java中构造器的作用主要是为了初始化变量的值...其实在执行构造器之前,Java对象所需要的内存空间,已经产生了... 一般可以 ...
- 2440移植内核到uboot上,打印乱码
转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/51851368 可能原因: 1. 修改内核 里的晶振大小 arch\arm\mach ...
- ES6学习之装饰器
定义:修饰器是一个对类进行处理的函数,用来修改类的行为 <注>:装饰器只能用来修改类及类的方法 类的装饰: 静态属性:只能通过类访问,修饰函数直接在类上操作 @testable class ...
- TCP/IP的3次握手和4次握手
在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接,如图1所示. (1) 第一次握手:建立连接时,客户端A发送SYN包(SYN=j)到服务器B,并进入SYN_SEND状态,等 ...
- HTTP 400 错误 编译器错误消息: CS0016
问题:运行程序时提示http 400错误 解决方法: 去掉勾 尝试将网页发布到本地IIS上,发现出现以下错误: 编译器错误消息: CS0016 解决编译器错误消息: CS0016:方法如下: 一般都是 ...
- 创建sharepoint网站
1.首先打开管理中心 输入用户名和密码(默认是本机的管理员名称及密码) 在“应用程序管理”选择“管理WEB应用程序” 新建应用程序 选择一个没有占用的端口,选择允许匿名访问 数据库名称一般为WSS_C ...
- [HDU3037]Saving Beans,插板法+lucas定理
[基本解题思路] 将n个相同的元素排成一行,n个元素之间出现了(n-1)个空档,现在我们用(m-1)个“档板”插入(n-1)个空档中,就把n个元素隔成有序的m份,每个组依次按组序号分到对应位置的几个元 ...
- 杭电acm 1033题
Problem Description For products that are wrapped in small packings it is necessary that the sheet o ...
- 大富翁开发日记:一、使用巨型lua协程
一个大胆的尝试:使用巨型lua协程来表示整个“一局”流程. lua协程是一个很另类的功能,有并发的影子但又不是真的并发,所以真正拿它来做大功能框架的范例不多,通常用于一些小型trick式设计.但这次我 ...
- 6.7 root和user之间的切换