当前位置:网站首页>PAT 乙等 1015 C语言
PAT 乙等 1015 C语言
2022-06-23 04:11:00 【章鱼bro】
1015. 德才论 (25)
宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”
现给出一批考生的德才分数,请根据司马光的理论给出录取排名。
输入格式:
输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线L的考生也按总分排序,但排在第三类考生之后。
随后N行,每行给出一位考生的信息,包括:准考证号、德分、才分,其中准考证号为8位整数,德才分为区间[0, 100]内的整数。数字间以空格分隔。
输出格式:
输出第1行首先给出达到最低分数线的考生人数M,随后M行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。
输入样例: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输出样例:
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
思路:因为每个学生的信息较多,故采用结构体存储
此题关键在于抓住两个排序:
在德才达到及格线的基础上
1.分数类型的排序,排序优先级为:
(1)德才都不低于优秀线
(2)德不低于优秀线且才低于优秀线
(3)德才均低于优秀线且德高于才
(4)其他(德低于优秀线而才高于有优秀线,德才均低于优秀线且才高于德)
2.同一分数类型排序
(1)总分
(2)德
(3)考号
一、起始变量
1.N(人数)、L(及格线)、H(优秀线)
2.存储学生信息的结构体数组
二、运算
1.录入结构体数组,并同时判断是否具有录取资格,即德才及格
2.分别按照四种成绩的要求进行录入
3.在每种成绩内部进行排序
4.输出
三、代码
#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;//表明不及格失去录取资格
}
else
{
students[i].flag = 1;
}
}
//德才兼备
student VAA[N];
int countOfVAA = 0;
//德胜才
student VANA[N];
int countOfVANA = 0;
//尚可德胜才
student NVANA[N];
int countOfNVANA = 0;
//其他
student base[N];
int countOfbase = 0;
for(int i = 0; i < N; i++)
{
//德才兼备
if(students[i].flag != 0 && students[i].virtue >= H && students[i].ability >= H)
{
VAA[countOfVAA] = students[i];
students[i].flag = 0;//在之后的判断中不用再划分此同学
countOfVAA++;
}
//德胜才
if(students[i].flag != 0 && students[i].virtue >= H && students[i].ability < H)
{
VANA[countOfVANA] = students[i];
students[i].flag = 0;
countOfVANA++;
}
//尚可德胜才
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++;
}
//其他
if(students[i].flag != 0)
{
base[countOfbase] = students[i];
students[i].flag = 0;
countOfbase++;
}
}
//四种成绩内部排序
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);
//输出
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;
//先比较总分
if( (one->virtue + one->ability) > (two->virtue + two->ability) )
{
return -1;
}
else if( (one->virtue + one->ability) < (two->virtue + two->ability) )
{
return 1;
}
else
{
//即德才分数相等 ,比较德
if(one->virtue > two->virtue)
{
return -1;
}
else if(one->virtue < two->virtue)
{
return 1;
}
else
{
//德分数相等,比较id
if(one->id > two->id)
{
return 1;
}
else
{
return -1;
}
}
}
}边栏推荐
- Opportunities and challenges of digital collections from the perspective of technology development team
- FS2119A同步升压IC输出3.3V和FS2119B同步升压IC输出5V
- IP6809三线圈15W无线充电发射端方案ic英集芯
- The 510000 prize pool invites you to participate in the competition -- the second Alibaba cloud ECS cloudbuild developer competition is coming
- visdom的使用
- Export PDF with watermark
- 高等数学(第七版)同济大学 习题1-7 个人解答
- Common wireless charging and transmitting IC chips
- STC 32位8051单片机开发实例教程 一 开发环境搭建
- Advanced Mathematics (Seventh Edition) Tongji University exercises 1-9 personal solutions
猜你喜欢

C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)

True question of MySQL interview (29) -- case - finding favorite movies

MySQL面试真题(二十九)——案例-找到爱看的电影

Wechat applet: Puzzle toolbox

Win11应用商店一直转圈解决办法

How to move the software downloaded from win11 app store to the desktop
![[proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale](/img/2d/96a370c90dcb7091038afad33bc4b4.png)
[proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale

MySQL面试真题(二十七)——RFM分析法对用户进行分类

云原生数据库是未来

What benefits have digital collections enabled the real industry to release?
随机推荐
Software design and Development Notes 2: serial port debugging tool based on QT design
Use of visdom
The performance of nonstandard sprintf code in different platforms
高等数学(第七版)同济大学 习题1-7 个人解答
Low cost 5W wireless charger scheme fs68001b simple charging chip
抽奖 ddd 代码
雷达图canvas
What is the reason for the black screen of the computer monitor when the computer is turned on? What should I do about the black screen of the computer monitor
sprintf 格式代码使用不规范在不同平台下的表现
手机无线充电双线圈15W方案SOC英集芯IP6809
True question of MySQL interview (29) -- case - finding favorite movies
Webrtc[47] - a common way for webrtc to save YUV data
The 510000 prize pool invites you to participate in the competition -- the second Alibaba cloud ECS cloudbuild developer competition is coming
Genetic engineering of AI art? Use # artbreeder to change any shape of the image
Mobile phone wireless charging dual coil 15W scheme SOC IC ip6809
基于SSM框架的借阅图书管理系统
数字化工厂建设可划分为三个方面
PAT 乙等 1011 C语言
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
STC 32比特8051單片機開發實例教程 一 開發環境搭建