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 ...
随机推荐
- Python图片识别——人工智能篇
一.安装pytesseract和PIL PIL全称:Python Imaging Library,python图像处理库,这个库支持多种文件格式,并提供了强大的图像处理和图形处理能力. 由于PIL仅 ...
- 使用pygame制作一个简单的游戏
翻译自Will McGugan的<Beginning Game Development with Python and Pygame –From Novice to Professional&g ...
- koa1创建项目
1.一定要全局安装(koa1.2和koa2都己经支持)npm install koa-generator -g 2.koa1.2 生成一个test项目,切到test目录并下载依赖 koa testcd ...
- 安装python Matplotlib 库
转:使用 python Matplotlib 库 绘图 及 相关问题 使用 python Matplotlib 库绘图 转:http://blog.csdn.net/daniel_ustc ...
- ssh远程转发使远程主机在所有ip上监听
起因:突然一夜之间电信扰拨号ip全变内网地址了,这样即使用了动态域名,绑定的也不是本机ip,外部无法访问了.虽然打电话找电信反映说是可以改回来,但必须先解决眼前的问题,访问内网服务器上的svn仓库. ...
- java中的几种架构对象(PO,VO,DAO,BO,POJO)
java中的几种对象(PO,VO,DAO,BO,POJO) 一.PO :(persistant object ),持久对象 可以看成是与数据库中的表相映射的java对象.使用Hibernate来生 ...
- ubuntu下apache2的cgi-bin中以root权限运行程序
一,安装apache2 sudo apt-get install apache2 二.配置cgi-bin sudo chmod 777 /var/www/html sudo vim /etc/apac ...
- From COM to COM 侯捷 1998.06.12
摘要: 本文簡介 C++ Object Model 和 Component Object Model 的基本概念,並引介四本書籍: 1. Inside The C++ Object Model 2. ...
- 利用表达式树Expression优化反射性能
最近做了一个.Net Core环境下,基于NPOI的Excel导入导出以及Word操作的服务封装,涉及到大量反射操作,在性能优化过程中使用到了表达式树,记录一下. Excel导入是相对比较麻烦的一块, ...
- Eclipse插件无法识别的解决方法汇总
参考 http://www.cnblogs.com/apollolee/archive/2013/06/18/3142243.html