# Analysis of the theory of virtue and talent

Title Description

Sima Guang, a historian of the Song Dynasty, has a famous "theory of virtue and talent" in Zizhi Tongjian: "therefore, it is called a saint to have all talent and virtue, a fool to have both talent and virtue, a gentleman to win virtue, and a fool to win virtue
Villain. Anyone who takes a man's skill should not be a saint, but a gentleman. It's better to get a villain than a fool. "
The scores of virtue and talent of a group of candidates are given. Please give the admission ranking according to Sima Guang's theory.

Enter description

Input line 1 gives three positive integers:
N (< = 105), i.e. the total number of candidates;
L (> = 60), which is the lowest score line for admission, that is, candidates whose moral score and talent score are not lower than l are eligible for admission;
H (< 100) is the priority admission line - those whose moral score and talent score are not lower than this line are defined as "full of talent and virtue", and such candidates are ranked from high to low according to the total score of morality and talent; The candidates who can't get the talent score but get the moral score line belong to "virtue wins talent", which is also sorted according to the total score, but they are ranked behind the first category of candidates; Candidates whose moral and talent scores are lower than h, but whose moral scores are not lower than talent scores belong to "both talent and morality" but still have "virtue and talent", which are sorted according to the total score, but ranked behind the second category of candidates;
Other candidates who reach the lowest line L are also ranked according to the total score, but they are behind the third category of candidates.
Then, in line N, each line gives the information of one candidate, including: admission ticket number, German score and talent score. The admission ticket number is an 8-digit integer, and the German talent score is an integer in the interval [0, 100]. Numbers are separated by spaces.

Output description

The first line of output first gives the number of candidates reaching the lowest score line M, 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 many candidates in a certain category
If the total score is the same, it shall be arranged in descending order according to its moral score; If the scores are also in parallel, they will be output in ascending order of the admission number.

Input example

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 example

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>

struct Stu{
int no;
int de;
int cai;
};

int main(){
int N,L,H;
scanf("%d %d %d",&N,&L,&H);
int i;
struct Stu s={};
struct Stu stus[N];
for(i=0;i<N;i++){
scanf("%d",&s.no);
scanf("%d",&s.de);
scanf("%d",&s.cai);
stus[i]=s;
}
int HR[N];
int LR[N];
int LLR[N];
int LLLR[N];
int hcount=0;
int lcount=0;
int llcount=0;
int lllcount=0;
for(i=0;i<N;i++){
if(stus[i].de >= H && stus[i].cai >= H){
HR[hcount++]=i;
}
if(stus[i].de >= H && stus[i].cai<H && stus[i].cai>=L){
LR[lcount++]=i;
}
if(stus[i].de< H && stus[i].de >=L && stus[i].cai<H && stus[i].cai>=L && stus[i].de>=stus[i].cai){
LLR[llcount++]=i;
}
if(stus[i].de< H && stus[i].de >=L && stus[i].cai>=L && stus[i].de<stus[i].cai){
LLLR[lllcount++]=i;
}
}
int all;
all=hcount+lcount+llcount+lllcount;
printf("%d\n",all);
int j;
for(i=0;i<hcount-1;i++){
int flag=0;
for(j=1;j<hcount-i;j++){
if((stus[HR[j-1]].de+stus[HR[j-1]].cai)<(stus[HR[j]].de+stus[HR[j]].cai)){
int tmp=HR[j-1];
HR[j-1]=HR[j];
HR[j]=tmp;
flag=1;
}else if((stus[HR[j-1]].de+stus[HR[j-1]].cai)==(stus[HR[j]].de+stus[HR[j]].cai)){
if(stus[HR[j-1]].de<stus[HR[j]].de){
int tmp=HR[j-1];
HR[j-1]=HR[j];
HR[j]=tmp;
flag=1;
}else if(stus[HR[j-1]].de==stus[HR[j]].de){
if(stus[HR[j-1]].no>stus[HR[j]].no){
int tmp=HR[j-1];
HR[j-1]=HR[j];
HR[j]=tmp;
flag=1;
}
}

}
}
if(flag==0){
break;
}
}
for(i=0;i<hcount;i++){
printf("%d %d %d\n",stus[HR[i]].no,stus[HR[i]].de,stus[HR[i]].cai);
}

for(i=0;i<lcount-1;i++){
int flag=0;
for(j=1;j<lcount-i;j++){
if((stus[LR[j-1]].de+stus[LR[j-1]].cai)<(stus[LR[j]].de+stus[LR[j]].cai)){
int tmp=LR[j-1];
LR[j-1]=LR[j];
LR[j]=tmp;
flag=1;
}else if((stus[LR[j-1]].de+stus[LR[j-1]].cai)==(stus[LR[j]].de+stus[LR[j]].cai)){
if(stus[LR[j-1]].de<stus[LR[j]].de){
int tmp=LR[j-1];
LR[j-1]=LR[j];
LR[j]=tmp;
flag=1;
}else if(stus[LR[j-1]].de==stus[LR[j]].de){
if(stus[LR[j-1]].no>stus[LR[j]].no){
int tmp=LR[j-1];
LR[j-1]=LR[j];
LR[j]=tmp;
flag=1;
}
}

}
}
if(flag==0){
break;
}
}
for(i=0;i<lcount;i++){
printf("%d %d %d\n",stus[LR[i]].no,stus[LR[i]].de,stus[LR[i]].cai);
}

for(i=0;i<llcount-1;i++){
int flag=0;
for(j=1;j<llcount-i;j++){
if((stus[LLR[j-1]].de+stus[LLR[j-1]].cai)<(stus[LLR[j]].de+stus[LLR[j]].cai)){
int tmp=LLR[j-1];
LLR[j-1]=LLR[j];
LLR[j]=tmp;
flag=1;
}else if((stus[LLR[j-1]].de+stus[LLR[j-1]].cai)==(stus[LLR[j]].de+stus[LLR[j]].cai)){
if(stus[LLR[j-1]].de<stus[LLR[j]].de){
int tmp=LLR[j-1];
LLR[j-1]=LLR[j];
LLR[j]=tmp;
flag=1;
}else if(stus[LLR[j-1]].de==stus[LLR[j]].de){
if(stus[LLR[j-1]].no>stus[LLR[j]].no){
int tmp=LLR[j-1];
LLR[j-1]=LLR[j];
LLR[j]=tmp;
flag=1;
}
}

}
}
if(flag==0){
break;
}
}
for(i=0;i<llcount;i++){
printf("%d %d %d\n",stus[LLR[i]].no,stus[LLR[i]].de,stus[LLR[i]].cai);
}

for(i=0;i<lllcount-1;i++){
int flag=0;
for(j=1;j<lllcount-i;j++){
if((stus[LLLR[j-1]].de+stus[LLLR[j-1]].cai)<(stus[LLLR[j]].de+stus[LLLR[j]].cai)){
int tmp=LLLR[j-1];
LLLR[j-1]=LLLR[j];
LLLR[j]=tmp;
flag=1;
}else if((stus[LLLR[j-1]].de+stus[LLLR[j-1]].cai)==(stus[LLLR[j]].de+stus[LLLR[j]].cai)){
if(stus[LLLR[j-1]].de<stus[LLLR[j]].de){
int tmp=LLLR[j-1];
LLLR[j-1]=LLLR[j];
LLLR[j]=tmp;
flag=1;
}else if(stus[LLLR[j-1]].de==stus[LLLR[j]].de){
if(stus[LLLR[j-1]].no>stus[LLLR[j]].no){
int tmp=LLLR[j-1];
LLLR[j-1]=LLLR[j];
LLLR[j]=tmp;
flag=1;
}
}

}
}
if(flag==0){
break;
}
}
for(i=0;i<lllcount;i++){
printf("%d %d %d\n",stus[LLLR[i]].no,stus[LLLR[i]].de,stus[LLLR[i]].cai);
}

return 0;
}

Keywords: PAT

Added by luddeb on Sun, 16 Jan 2022 01:58:16 +0200