PAT Level B | 1015 Theory of Virtue and Talent (25 points)

Sima Guang, a historian of the Song Dynasty, has a famous "Theory of Virtue and Talent" in "Tongjian of Zizhi": "He is a saint whose talents and virtues are exhausted; Shengde is called a villain. The art of taking people is not a sage, and a gentleman should follow it. It is not a fool to win a villain."

Now give out the scores of a group of candidates, please give the admission ranking according to Sima Guang's theory.

Input format:

Enter the first line to give 3 positive integers, which are: N (≤10 5 ), which is the total number of candidates; L (≥60), is the minimum admission score, that is, candidates whose moral and talent points are not lower than L Eligible to be considered for admission; H (<100), is the priority admission line-those whose virtue and talent points are not lower than this line are defined as "exhaustion of talents and virtues". Such candidates will be based on their total scores Candidates who can’t be scored but whose virtue is on the line belong to the category of “Virtue Shengcai” and are also ranked by total score, but they are ranked after the first category candidates; the scores of virtue and talent are all lower than H, but the score is lower Candidates with a score of no less than talents belong to the "death of talents and morals" but still have "successful virtues". They are ranked by total score, but they are ranked after the second category candidates; other candidates who reach the lowest line L are also ranked by total score , But ranked behind the third category of candidates.

Next N lines, each line gives information about one candidate, including: Admission Ticket Number, which is an 8-digit integer, and Decai is an integer in the interval [0, 100]. The numbers are separated by spaces.

Output format:

The first line of output first gives the number of candidates M who reach the lowest score line, and then M lines. Each line outputs the information of one candidate according to the input format. The candidates are sorted from high to low according to the rules described in the input. When multiple candidates in a certain category have the same total score, they are sorted in descending order of their virtue points; if their virtue points are also tied, they will be output in ascending order of admission ticket number.

Input sample:

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

Idea: This question has a large amount of information, and a little carelessness may be embarrassed. You can use the sort function in STL to sort, but this question needs to know the hidden condition, which is to set a priority.

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int l,h;

struct student{
    
    
    int number;
    int de_fen;
    int cai_fen;
    int total;
    int priority;
}stu[100000];

bool cmp(student a,student b){
    
    
	if(a.priority!=b.priority) return a.priority<b.priority;
	if(a.total!=b.total) return a.total>b.total;
	if(a.de_fen!=b.de_fen) return a.de_fen>b.de_fen;
	return a.number<b.number;
}

int main()
{
    
    
    int n,cnt=0;
    int a,b,c;
    cin >>n>>l>>h;
    for(int i=0;i<n;i++){
    
    
        scanf("%d%d%d",&a,&b,&c);
        if(b>=l&&c>=l){
    
    
            stu[cnt].number=a;
            stu[cnt].de_fen=b;
            stu[cnt].cai_fen=c;
            stu[cnt].total=stu[cnt].de_fen+stu[cnt].cai_fen;
            if(stu[cnt].de_fen>=h&&stu[cnt].cai_fen>=h)
            	stu[cnt].priority=1;
            else if(stu[cnt].de_fen>=h&&stu[cnt].cai_fen<h)
            	stu[cnt].priority=2;
            else if(stu[cnt].de_fen<h&&stu[cnt].cai_fen<h&&stu[cnt].de_fen>=stu[cnt].cai_fen)
            	stu[cnt].priority=3;
            else
            	stu[cnt].priority=4;
            cnt++;
        }
    }
    sort(stu,stu+cnt,cmp);
    cout <<cnt<<endl;
    for(int i=0;i<cnt;i++)
        printf("%08d %d %d\n",stu[i].number,stu[i].de_fen,stu[i].cai_fen);
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_44888152/article/details/108629600