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 ...
随机推荐
- hashcode和equals
Java中集合(Collection):一类是List另外一类是Set: 区别:list中元素有序,可重复 Set元素无序,不能重复 如何保证元素不重复呢?Object.Equals 但是当添加的元素 ...
- Nodejs调试技术
基于Chrome浏览器的调试器 既然我们可以通过V8的调试插件来调试,那是否也可以借用Chrome浏览器的JavaScript调试器来调试呢?node-inspector模块提供了这样一种可能.我们需 ...
- JSP编译指令
----------------siwuxie095 编译指令是通知 JSP 引擎的消息,其作用是设置 JSP 程序的属性, 以及由 JSP 生 ...
- SpringSecurity02 表单登录、SpringSecurity配置类
1 功能需求 springSecuriy默认的登录窗口是一个弹出窗口,而且会默认对所有的请求都进行拦截:要求更改登录页面(使用表单登录).排除掉一些请求的拦截 2 编写一个springSecurity ...
- [原创]SQL 表值函数:获取从今天计算起往前自定义天数
PS:此博文是利用Windows Live Writer 2012编写,格式效果可能不太好. 在我开发过程中,遇到一个统计需求,结果是要求返回从当天起往回推算出自定义输入的天数 为此我写了一个表值函数 ...
- OpenGL 使用GLFW创建全屏窗口
OpenGL 使用GLFW创建全屏窗口 GLFW库里面的glfwCreateWindow()函数是用来创建窗口的函数. 这样函数的原型是: GLFWwindow* glfwCreateWindow(i ...
- 2、linux-compress and uncompresse
1.单个文件 压缩 解压 gzip file1 gzip -d file1.gz或者gunzip file1.gz #file1文件即会被压缩为 file1.gz,file1原文件删除:解压后同样删 ...
- sublime text 侧边栏样式修改
安装PackageResourceViewer 插件.快捷键 CTRL+SHIFT+P 打开 命令面板,输入 Package Control:Install Package (直接输入PCIP,四个单 ...
- 23.通过MS17_010来学习msf对渗透的利用
Metersploit 集成了渗透阶段的全部利用,从漏洞探测,到漏洞利用,最后到后渗透阶段.本次博客主要抛砖引玉,通过对MS17_010漏洞的复现,来学习Metasploit. 漏洞环境: 靶机:wi ...
- redis学习总结1
Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.和普通的Key-Value结构不同,Redis的Key支持灵活 ...