PAT_A1062#Talent and Virtue
Source:
Description:
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 (≤), the total number of people to be ranked; L (≥), 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 (<), 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 Lline 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_Numberis 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 (≤), 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
Keys:
- 模拟题
Code:
/*
Data: 2019-07-15 18:19:51
Problem: PAT_A1062#Talent and Virtue
AC: 18:55 题目大意:
圣人:德才 >= H
君子:德 >= H
愚人:德 >= 才
小人:余下者
输入:
第一行给出,人数N<=1e5,及格线L>=60,优秀线H<100
接下来N行,id,virture, talent
输出:
第一行给出,有效人数M
接下来M行,按照圣人,君子,愚人,小人的顺序,按成绩递减输出(德才,德,id)
*/ #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct node
{
int id,mark;
int vir,tal;
}temp;
vector<node> ans; bool cmp(const node &a, const node &b)
{
if(a.mark != b.mark)
return a.mark < b.mark;
else if(a.vir+a.tal != b.vir+b.tal)
return a.vir+a.tal > b.vir+b.tal;
else if(a.vir != b.vir)
return a.vir > b.vir;
else
return a.id < b.id;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,l,h;
scanf("%d%d%d", &n,&l,&h);
for(int i=; i<n; i++)
{
scanf("%d%d%d", &temp.id,&temp.vir,&temp.tal);
if(temp.vir>=l && temp.tal>=l)
{
if(temp.vir>=h && temp.tal>=h)
temp.mark=;
else if(temp.vir>=h)
temp.mark=;
else if(temp.vir>=temp.tal)
temp.mark=;
else
temp.mark=;
ans.push_back(temp);
}
}
sort(ans.begin(),ans.end(),cmp);
printf("%d\n", ans.size());
for(int i=; i<ans.size(); i++)
printf("%08d %d %d\n", ans[i].id,ans[i].vir,ans[i].tal); return ;
}
PAT_A1062#Talent and Virtue的更多相关文章
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)
1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vecto ...
- 1062.Talent and Virtue
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
- 1062 Talent and Virtue (25 分)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- PAT 1062 Talent and Virtue[难]
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- PAT 1062 Talent and Virtue
#include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #i ...
- pat1062. Talent and Virtue (25)
1062. Talent and Virtue (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Li Abou ...
- 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 ...
随机推荐
- git push 报错:failed to push some refs to 'git@git.xxxx:devops/thor.git'
error: failed to push some refs to 'git@git.caicaivip.com:devops/thor.git' hint: Updates were reject ...
- SCI小论文投稿记录
英文小论文投的是SCI 3区的一个刊物,收录在spring,ei等, 投稿的时候2019/2/3影响因子2.8左右 现在2019/8/13 影响因子3.844 先科普下论文的各个状态 1. Subm ...
- Spring Cloud Alibaba
Spring Cloud Alibaba Dubbo Dubbo Dubbo 系列 [Dubbo 系列总结] [Dubbo 系列(01)最简使用姿态] [Dubbo 系列(02)整体架构] Dubbo ...
- docker swarm创建swarm集群
三台linux主机 manager:192.168.100.151 work1:192.168.100.156 work2:192.168.100.157 manager docker swarm i ...
- Queue与Deque的区别
前言 在研究java集合源码的时候,发现了一个很少用但是很有趣的点:Queue以及Deque,平常在写leetcode经常用LinkedList向上转型Deque作为栈或者队列使用,但是一直都不知 ...
- 17-vim-查找字符或单词-02-查找并替换
在vi中查找和替换命令需要在末行模式下执行. 命令 功能 :%s///g 末行模式下,查找并替换字符.例:%s /hello/world/g 1.全局替换 一次性替换文件中的所有文件的旧文本. 命令格 ...
- apache下logs下的日志文件简单说明
一.日志分析 如果apache的安装时采用默认的配置,那么在/logs目录下就会生成两个文件,分别是access_log和error_log 1).access_log access_log为访问日志 ...
- Spark和pyspark的配置安装
如何安装Spark和Pyspark构建Spark学习环境[MacOs] JDK环境 Python环境 Spark引擎 下载地址:Apache-Spark官网 MacOs下一般安装在/usr/local ...
- elastic插件安装
https://blog.csdn.net/dwyane__wade/article/details/80191131 参考这篇博文,唯一不同是,下面这一步可以不用,直接启动就行
- docker linux基本操作
容器运行起来之后一些基本的工具还是要安装好: 这个工具的安装方式和linux是一样的,因为容器本身就是一个微linux系统 先安装 apt, 1 / apt-get update 安装了apt之后 可 ...