Basic Level 1015 Theory of Virtue and Talent (25 points)

topic

The historian Sima Guang of the Song Dynasty has a famous "Theory of Virtue and Talent" in the "Tongjian of Zizhi": "It is a saint who is full of talents and virtues, and a fool who is both talented and virtuous. 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 a group of candidates’ scores of virtue and talent, please give the admission ranking according to Sima Guang’s theory.

Input format:

Enter the first line to give 3 positive integers, respectively: N (≤ 1 0 5) N (≤ 10^5)N105 ), is the total number of candidates; L (≥60), is the minimum admission score, that is, only candidates whose moral and talent scores are not lower than L are eligible to be considered for admission; H (<100) is the priority admission line—— Candidates whose scores of virtue and talent are not lower than this line are defined as "exhaustion of talents and virtues". This category of candidates is sorted from high to low in terms of total scores of virtue and talent; candidates who have no score but reach the line belong to the category "Virtue Shengcai" is also sorted by total score, but ranks after the first category of candidates; candidates whose morality and talent scores are all lower than H, but whose morality score is not lower than talent scores belong to "talent and morality" but still have " "Deshengcai" candidates are sorted by total score, but after the second-category candidates; other candidates who reach the lowest line L are also sorted by total score, but are ranked after the third-category 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, and the candidates are sorted from high to low according to the rules described in the input. When there are multiple candidates in a certain category with the same total score, they will be 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

Thinking analysis:

Use structured questions to save, write a comparison function for the parameter cmp, and then save the candidates for each class separately.

Code:

#include <bits/stdc++.h>
using namespace std;
struct student{
    
    
    int id, de, cai;
}stu[4][100010], tmp;
bool cmp(student a, student b){
    
    
    if((a.de + a.cai) != (b.de + b.cai)) return (a.de + a.cai) > (b.de + b.cai);
    else if(a.de != b.de) return a.de > b.de;
    else return a.id < b.id;
}
int main(){
    
    
    int N, L, H, k[4] = {
    
    0};
    scanf("%d %d %d", &N, &L, &H);
    int res = N;
    for(int i = 0; i < N; i++){
    
    
        scanf("%d %d %d", &tmp.id, &tmp.de, &tmp.cai);
        if(tmp.de < L || tmp.cai < L) res--;
        else if(tmp.de >= H && tmp.cai >= H) stu[0][k[0]++] = tmp;
        else if(tmp.de >= H && tmp.cai < H) stu[1][k[1]++] = tmp;
        else if(tmp.de < H && tmp.cai < H && tmp.de >= tmp.cai) stu[2][k[2]++] = tmp;
        else stu[3][k[3]++] = tmp;
    }
    printf("%d\n", res);
    for(int i = 0; i < 4; i++){
    
    
        sort(stu[i], stu[i] + k[i], cmp);
        for(int j = 0; j < k[i]; j++)
            printf("%d %d %d\n", stu[i][j].id, stu[i][j].de, stu[i][j].cai);
    }
    return 0;
}

PAT_BasicLevel

Guess you like

Origin blog.csdn.net/zy440458/article/details/113802648