1015 Theory of Virtue and Talent (25 points) - PAT (Basic Level) Practice (Chinese)

Posted by expertis on Tue, 17 Sep 2019 15:02:34 +0200

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 Zizhi Tongjian: "It is the sage who has all talent and virtue, the fool who has both talent and virtue, the gentleman who wins virtue and the villain who wins virtue. Whoever takes a man's skill must not be a saint, but a gentleman, rather than a villain, should not be a fool."

Given a number of candidates'moral and talent scores, please give the admission ranking according to Sima Guang's theory.

Input format:
The first line of input gives three positive integers: N (< 10).
​5
L (> 60) is the lowest admission score, that is, candidates whose moral and talent scores are not less than L are eligible to be considered for admission; H (< 100) is the preferential admission line, where both moral and talent scores are not less than this line is defined as "all talents and virtues are exhausted". Such candidates are ranked from high to low according to their total moral and talent scores. A class of candidates who can't get a mark but whose moral score is on the line belongs to the category of "virtue wins talent" and ranks according to the total score, but ranks behind the first category of candidates; candidates whose moral score is lower than H, but whose moral score is not lower than that of talent belong to the category of "both talent and virtue die", but those who still have "virtue wins talent" rank according to the total score, but rank behind the second category of candidates; others reach the same level. The lowest L candidates are also ranked according to the total score, but behind the third category.

Subsequently, N lines, each line gives a candidate's information, including: the admission number, moral score, which is 8 integers, moral score is divided into intervals [0, 100] integers. Numbers are separated by spaces.

Output format:
The first line of output first gives the number of candidates to reach the lowest score line M, then M lines, each line according to the input format to output a candidate's information, candidates according to the rules described in the input from high to low. When the total scores of many candidates in a certain category are the same, they are arranged in descending order according to their morality scores; if the morality scores are also juxtaposed, they are output in ascending order according to the admission 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
Output sample:
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

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Student
{
	int name;	
	int de;
	int cai;
	int sum;
}love1[100100],love2[100100],love3[100100],love4[100100],love5[100100];	//Love 1 is the total student 
int comp(const void* a,const void* b)
{
	struct Student *aa = (struct Student *)a;
	struct Student *bb = (struct Student *)b;
	if(aa->sum != bb->sum)
	return ((bb->sum) - (aa->sum));
	else if(aa->de != bb->de)
	return ((bb->de) - (aa->de));
	else
	return ((aa->name) - (bb->name));
}
int main()
{
	int one=0,two=0,three=0,four=0,five=0;
	int i,j;
	int N,L,H;
	scanf("%d%d%d",&N,&L,&H);
	for(i=0;i<N;i++)
	{
		scanf("%d%d%d",&love1[i].name,&love1[i].de,&love1[i].cai);
		love1[i].sum = love1[i].de+love1[i].cai;
	}
	for(i=0;i<N;i++)
	{
		if(love1[i].de>=L && love1[i].cai>=L)
		{
			one++;
			if(love1[i].de>=H && love1[i].cai>=H)
			{	love2[two] = love1[i];		two++;		}
			else if(love1[i].cai<H && love1[i].de>=H)
			{	love3[three] = love1[i];	three++;	}
			else if(love1[i].de<H && love1[i].cai<H && love1[i].de>=love1[i].cai)
			{	love4[four] = love1[i];		four++;		}
			else
			{	love5[five] = love1[i];		five++;		}		
		}
	}
	printf("%d\n",one);
	qsort(love2,two,sizeof(love2[0]),comp);
	qsort(love3,three,sizeof(love3[0]),comp);
	qsort(love4,four,sizeof(love4[0]),comp);
	qsort(love5,five,sizeof(love5[0]),comp);
	
	for(i=0;i<two;i++)
	printf("%d %d %d\n",love2[i].name,love2[i].de,love2[i].cai);
	for(i=0;i<three;i++)
	printf("%d %d %d\n",love3[i].name,love3[i].de,love3[i].cai);
	for(i=0;i<four;i++)
	printf("%d %d %d\n",love4[i].name,love4[i].de,love4[i].cai);
	for(i=0;i<five;i++)
	printf("%d %d %d\n",love5[i].name,love5[i].de,love5[i].cai);
}

Topics: less