其他分享
首页 > 其他分享> > PAT_A1062#Talent and Virtue

PAT_A1062#Talent and Virtue

作者:互联网

Source:

PAT A1062 Talent and Virtue (25 分)

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_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

Keys:

Code:

 1 /*
 2 Data: 2019-07-15 18:19:51
 3 Problem: PAT_A1062#Talent and Virtue
 4 AC: 18:55
 5 
 6 题目大意:
 7 圣人:德才 >= H
 8 君子:德 >= H
 9 愚人:德 >= 才
10 小人:余下者
11 输入:
12 第一行给出,人数N<=1e5,及格线L>=60,优秀线H<100
13 接下来N行,id,virture, talent
14 输出:
15 第一行给出,有效人数M
16 接下来M行,按照圣人,君子,愚人,小人的顺序,按成绩递减输出(德才,德,id)
17 */
18 
19 #include<cstdio>
20 #include<vector>
21 #include<algorithm>
22 using namespace std;
23 struct node
24 {
25     int id,mark;
26     int vir,tal;
27 }temp;
28 vector<node> ans;
29 
30 bool cmp(const node &a, const node &b)
31 {
32     if(a.mark != b.mark)
33         return a.mark < b.mark;
34     else if(a.vir+a.tal != b.vir+b.tal)
35         return a.vir+a.tal > b.vir+b.tal;
36     else if(a.vir != b.vir)
37         return a.vir > b.vir;
38     else
39         return a.id < b.id;
40 }
41 
42 int main()
43 {
44 #ifdef    ONLINE_JUDGE
45 #else
46     freopen("Test.txt", "r", stdin);
47 #endif
48 
49     int n,l,h;
50     scanf("%d%d%d", &n,&l,&h);
51     for(int i=0; i<n; i++)
52     {
53         scanf("%d%d%d", &temp.id,&temp.vir,&temp.tal);
54         if(temp.vir>=l && temp.tal>=l)
55         {
56             if(temp.vir>=h && temp.tal>=h)
57                 temp.mark=1;
58             else if(temp.vir>=h)
59                 temp.mark=2;
60             else if(temp.vir>=temp.tal)
61                 temp.mark=3;
62             else
63                 temp.mark=4;
64             ans.push_back(temp);
65         }
66     }
67     sort(ans.begin(),ans.end(),cmp);
68     printf("%d\n", ans.size());
69     for(int i=0; i<ans.size(); i++)
70         printf("%08d %d %d\n", ans[i].id,ans[i].vir,ans[i].tal);
71 
72     return 0;
73 }

 

标签:PAT,temp,mark,vir,90,tal,Talent,80,A1062
来源: https://www.cnblogs.com/blue-lin/p/11190681.html