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 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 (≤), 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
题目分析:想直接在一个vector处理 但是导致compare函数写的不对 在读入数据时 就将属于不同类别的先归类 再进行排序
 #define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
struct Person {
int Id;
int Vir_Grade;
int Tal_Grade;
};
int N, L, H;
vector<Person> P[];
bool compare(const Person& a, const Person& b)
{
int Grade_a = a.Tal_Grade + a.Vir_Grade;
int Grade_b = b.Tal_Grade + b.Vir_Grade;
if (Grade_a != Grade_b)
return Grade_a > Grade_b;
else if (a.Vir_Grade != b.Vir_Grade)
return a.Vir_Grade > b.Vir_Grade;
else return a.Id < b.Id;
}
int main()
{ scanf("%d %d %d", &N,&L,&H);
for(int i=;i<N;i++)
{
int id;
int V_Grade, T_Grade;
scanf("%d %d %d", &id, &V_Grade, &T_Grade);
if (V_Grade < L || T_Grade < L)continue;
if (V_Grade >= H && T_Grade >= H)
P[].push_back({ id,V_Grade,T_Grade });
else if (V_Grade>=H && T_Grade < H)
P[].push_back({ id,V_Grade,T_Grade });
else if(V_Grade<H&&T_Grade<H&&V_Grade>=T_Grade)
P[].push_back({ id,V_Grade,T_Grade });
else
P[].push_back({ id,V_Grade,T_Grade });
}
int size = ;
for (int i = ; i <; i++)
{
size += P[i].size();
sort(P[i].begin(), P[i].end(), compare);
}
cout << size << endl;
for (int i = ; i < ; i++)
for (auto it : P[i])
cout << it.Id << " " << it.Vir_Grade << " " << it.Tal_Grade << endl;
return ;
}

1062 Talent and Virtue (25分)(水)的更多相关文章

  1. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  2. PAT甲题题解-1062. Talent and Virtue (25)-排序水题

    水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...

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

    题意: 输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线.接着输入N行数据,每行包括一个人的ID,道德数值和才能数值.一 ...

  4. 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 ...

  5. 1062 Talent and Virtue (25)

    /* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...

  6. pat 1062. Talent and Virtue (25)

    难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...

  7. PAT (Advanced Level) 1062. Talent and Virtue (25)

    简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...

  8. pat1062. Talent and Virtue (25)

    1062. Talent and Virtue (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Li Abou ...

  9. 1062 Talent and Virtue (25 分)

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

随机推荐

  1. 结题报告--P2441角色属性树

    题目:点此 题目描述 绪萌同人社是一个有趣的组织,该组织结构是一个树形结构.有一个社长,直接下属一些副社长.每个副社长又直接下属一些部长……. 每个成员都有一个萌点的属性,萌点属性是由一些质数的萌元素 ...

  2. mysql中实现更新数据+1,再次更新数据-1

    $sql="update article set comment=comment^1 where a_id=2"; 这条语句你会发现当你更新comment字段时为1,再次更新时为0 ...

  3. 5G 将带给程序员哪些新机会呢?

    5G,第 5 代移动通信技术,华为在此领域远远领先同行,这也让它成了中美贸易战的最前线.我的第一份工作就在通信行业,当时电信标准都在欧美企业手里,国内企业主要是遵照标准研发软硬件设备,核心芯片靠进口. ...

  4. go例子(一) 使用go语言实现linux内核中的list_head

    package list 代码 package list import ( "fmt" ) // 数据接口 type ElemType interface{} // 节点 type ...

  5. Java 并发同步工具(转)

    转自:https://www.jianshu.com/p/e80043ac4115 在 java 1.5 中,提供了一些非常有用的辅助类来帮助我们进行并发编程,比如 CountDownLatch,Cy ...

  6. Java 锁详解(转)

    转自 https://www.cnblogs.com/jyroy/p/11365935.html Java提供了种类丰富的锁,每种锁因其特性的不同,在适当的场景下能够展现出非常高的效率.本文旨在对锁相 ...

  7. 一段很简单的PHP代码,用于手机拨号

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 【TIJ4】第三章全部习题

    题目都相当简单没啥说的直接放代码就行了... 3.1 package ex0301; //[3.1]使用“简短的”和正常的打印语句来写一个程序 import static java.lang.Syst ...

  9. No compiler is provided in this environment报错解决方案

  10. 从零开始学习R语言(二)——数据结构之“因素(Factor)”

    本文首发于知乎专栏:https://zhuanlan.zhihu.com/p/60101041 也同步更新于我的个人博客:https://www.cnblogs.com/nickwu/p/125370 ...