当前位置:网站首页>Pat class B 1015 C language
Pat class B 1015 C language
2022-06-23 05:57:00 【Octopus bro】
1015. On virtue and talent (25)
Sima Guang, a historian of the Song Dynasty 《 History As A Mirror 》 There is a famous passage in “ On virtue and talent ”:“ That's why we call it a saint , It's a fool to have both talent and morality , Virtue is a gentleman , Cai Shengde is called villain . The art of taking people , Not a saint , It's a gentleman , It's better to be a villain , If you don't get a fool .”
Here are the scores of a group of candidates , Please give the admission ranking according to Sima Guang's theory .
Input format :
Enter the first 1 Line is given 3 A positive integer , Respectively :N(<=105), That is, the total number of candidates ;L(>=60), For the lowest score , That is, both moral and talent scores are no less than L Candidates are eligible to be considered for Admission ;H(<100), For the priority admission line —— Those whose moral and talent scores are not lower than this line are defined as “ Just do everything ”, Such candidates are ranked from high to low according to the total score of virtue and talent ; The examinees who can't get the score but get the score line belong to “ Deshengcai ”, Also sort by total score , But after the first category of candidates ; Both moral and talent scores are lower than H, But candidates with a moral score of no less than talent belong to “ Both talent and morality ” But there is still “ Deshengcai ” person , Sort by total score , But after the second category of candidates ; Others reach the lowest line L The candidates are also ranked according to the total score , But after the third category of candidates .
And then N That's ok , Each line gives the information of one candidate , Include : Ticket number 、 Defen 、 Talent , The admission number is 8 An integer , Virtue and talent are divided into intervals [0, 100] The whole number inside . Numbers are separated by spaces .
Output format :
Output No 1 The first line gives the number of candidates who have reached the lowest score line M, And then M That's ok , Each line outputs the information of one candidate according to the input format , Candidates are sorted from high to low according to the rules described in the input . When there are more than one examinee in a certain category, they always share the same score , In descending order of virtue ; If the German points are also tied , Then it will be output in ascending order of the admission certificate number .
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 60sample 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
Ideas : Because each student has more information , Therefore, the structure is used to store
The key to this question is to grasp the two sorts :
On the basis that virtue and talent have reached the pass line
1. Sorting of score types , The priority is :
(1) Virtue and talent are not lower than the excellent level
(2) Virtue is not lower than the excellent line and only lower than the excellent line
(3) Both virtue and talent are lower than the excellent level and virtue is higher than talent
(4) other ( Virtue is lower than the excellent line but higher than the excellent line , Both virtue and talent are lower than the excellent line and talent is higher than virtue )
2. Sort the same score type
(1) Total score
(2) Virtue
(3) Examination number
One 、 Starting variable
1.N( The number of )、L( Pass line )、H( Excellent line )
2. An array of structures for storing student information
Two 、 operation
1. Enter the structure array , At the same time, judge whether they are qualified for admission , That is to say, virtue and talent pass the exam
2. Enter according to the requirements of the four grades
3. Sort within each grade
4. Output
3、 ... and 、 Code
#include "stdio.h"
#include "stdlib.h"
typedef struct{
int id;
int virtue;
int ability;
int flag;
}student;
int cmp(const void * a, const void * b);
int main()
{
int N, L, H;
scanf("%d %d %d",&N, &L, &H);
student students[N];
for(int i = 0; i < N; i++)
{
scanf("%d %d %d",&students[i].id,&students[i].virtue,&students[i].ability);
if(students[i].ability < L || students[i].virtue < L)
{
students[i].flag = 0;// It means that you will lose your admission qualification if you fail
}
else
{
students[i].flag = 1;
}
}
// Having both ability and political integrity
student VAA[N];
int countOfVAA = 0;
// Deshengcai
student VANA[N];
int countOfVANA = 0;
// It is only by virtue that we can win
student NVANA[N];
int countOfNVANA = 0;
// other
student base[N];
int countOfbase = 0;
for(int i = 0; i < N; i++)
{
// Having both ability and political integrity
if(students[i].flag != 0 && students[i].virtue >= H && students[i].ability >= H)
{
VAA[countOfVAA] = students[i];
students[i].flag = 0;// There is no need to divide this student in the later judgment
countOfVAA++;
}
// Deshengcai
if(students[i].flag != 0 && students[i].virtue >= H && students[i].ability < H)
{
VANA[countOfVANA] = students[i];
students[i].flag = 0;
countOfVANA++;
}
// It is only by virtue that we can win
if(students[i].flag != 0 && students[i].virtue < H && students[i].ability < H && students[i].virtue >= students[i].ability)
{
NVANA[countOfNVANA] = students[i];
students[i].flag = 0;
countOfNVANA++;
}
// other
if(students[i].flag != 0)
{
base[countOfbase] = students[i];
students[i].flag = 0;
countOfbase++;
}
}
// Internal ranking of four grades
qsort(VAA,countOfVAA,sizeof(VAA[0]),cmp);
qsort(VANA,countOfVANA,sizeof(VANA[0]),cmp);
qsort(NVANA,countOfNVANA,sizeof(NVANA[0]),cmp);
qsort(base,countOfbase,sizeof(base[0]),cmp);
// Output
printf("%d\n",countOfVAA + countOfVANA + countOfNVANA + countOfbase);
for(int i = 0; i < countOfVAA; i++)
{
printf("%08d %d %d\n",VAA[i].id,VAA[i].virtue,VAA[i].ability);
}
for(int i = 0; i < countOfVANA; i++)
{
printf("%08d %d %d\n",VANA[i].id,VANA[i].virtue,VANA[i].ability);
}
for(int i = 0; i < countOfNVANA; i++)
{
printf("%08d %d %d\n",NVANA[i].id,NVANA[i].virtue,NVANA[i].ability);
}
for(int i = 0; i < countOfbase; i++)
{
printf("%08d %d %d\n",base[i].id,base[i].virtue,base[i].ability);
}
return 0;
}
int cmp(const void * a, const void * b)
{
student * one = (student *)a;
student * two = (student *)b;
// First compare the total score
if( (one->virtue + one->ability) > (two->virtue + two->ability) )
{
return -1;
}
else if( (one->virtue + one->ability) < (two->virtue + two->ability) )
{
return 1;
}
else
{
// That is, the scores of virtue and talent are equal , Comparative virtue
if(one->virtue > two->virtue)
{
return -1;
}
else if(one->virtue < two->virtue)
{
return 1;
}
else
{
// The German scores are equal , Compare id
if(one->id > two->id)
{
return 1;
}
else
{
return -1;
}
}
}
}边栏推荐
- [proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale
- True MySQL interview question (24) -- row column exchange
- TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.3 全双工, 节能, 自动协商机制, 802.1X 流控制 / 3.3.3 链路层流量控制
- About the error of installing PIP3 install chatterbot
- MySQL面试真题(二十六)——滴滴2020年笔试题
- 云原生数据库是未来
- 编址和编址单位
- Real MySQL interview question (23) -- pinduoduo ball game analysis
- App SHA1 acquisition program Baidu map Gaode map simple program for acquiring SHA1 value
- 华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位
猜你喜欢

jvm-03.jvm内存模型

Wechat applet: wechat can also send flash photos to create wechat applet source code download and customize flash time

Explicability of counter attack based on optimal transmission theory

How can digital collections empower economic entities?
![[Stanford Jiwang cs144 project] lab2: tcpreceiver](/img/70/ceeca89e144907226f29575def0e4d.png)
[Stanford Jiwang cs144 project] lab2: tcpreceiver

Raspberry pie assert preliminary exercise

制造业数字化转型存在问题及原因分析

雷达图canvas

The construction of digital factory can be divided into three aspects

Real MySQL interview question (23) -- pinduoduo ball game analysis
随机推荐
Pit filling for abandoned openssl-1.0.2 (.A to.So)
PAT 乙等 1020.月饼
Pat class B 1014 C language
Wechat applet: wechat can also send flash photos to create wechat applet source code download and customize flash time
Arctime makes Chinese and English subtitle video
A bit of knowledge - folding forging and Damascus steel
True MySQL interview question (21) - Finance - overdue loan
雷达图canvas
Real MySQL interview questions (XXVII) -- Classification of users by RFM analysis method
制造业数字化转型存在问题及原因分析
MySQL面试真题(二十三)——拼多多-球赛分析
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
The difference between SaaS software and traditional software delivery mode
True MySQL interview question (XXII) -- condition screening and grouping screening after table connection
How can digital collections empower economic entities?
Excel sheet column number for leetcode topic resolution
PAT 乙等 1019 C语言
jvm-01. Instruction rearrangement
jvm-02. Guarantee of orderliness
PAT 乙等 1015 C语言