PAT乙级 1015. 德才论 (25)
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
--------------------------------------------------------------------
需要用到自带函数qsort
#include "stdio.h"
#include"string.h"
#include <stdlib.h> typedef struct stu
{
int number;
int de;
int cai;
int sum;
int type;
}stu;
void Swap(int *a,int *b);
int compar(const void *pa, const void *pb);
int get_type(int de, int cai);
int L=,H=;
int main()
{
stu *student;
int i,N=;
int cc=;
scanf("%d %d %d",&N,&L,&H);
student=(stu*)malloc(N*sizeof(stu));
for(i=;i<N;i++)
{ scanf("%d %d %d",&student[i].number,&student[i].de,&student[i].cai);
student[i].sum= student[i].cai+ student[i].de;
student[i].type = get_type(student[i].de, student[i].cai);
if (student[i].type != ) {
cc++;
}
} printf("%d\n",cc);
qsort(student, N, sizeof(*student), compar); for ( i = ; i < ac+bc+cc+dc; i++) {
printf("%d %d %d\n", student[i].number, student[i].de, student[i].cai);
} free(student); return ;
} int compar(const void *pa, const void *pb)
{
stu a = *(stu *)pa;
stu b = *(stu *)pb;
int ret;
if (a.type == b.type) {
if (a.sum == b.sum) {
if (a.de == b.de) {
ret = a.number - b.number;
} else {
ret = b.de - a.de;
}
} else {
ret = b.sum - a.sum;
}
} else {
ret = a.type - b.type;
}
return ret;
}
int get_type(int de, int cai)
{
int type;
if (de >= H) {
if (cai >= H) {
type = ;
} else if (cai >= L) {
type = ;
} else {
type = ;
}
} else if (de >= L) {
if (cai >= H) {
type = ;
} else if (cai >= L) {
if (de >= cai) {
type = ;
} else {
type = ;
}
} else {
type = ;
}
} else {
type = ;
}
return type;
}
PAT乙级 1015. 德才论 (25)的更多相关文章
- pat 乙级 1015. 德才论 (25) c++
http://39.106.25.239 个人网站 欢迎访问 交流 1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Sta ...
- 【PAT】1015 德才论 (25)(25 分)
1015 德才论 (25)(25 分) 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得 ...
- PAT Basic 1015 德才论 (25 分)
宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人 ...
- PAT乙级:1015 德才论 (25分)
1015 德才论 (25分) 宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人 ...
- PAT 1015 德才论 (25)(代码+思路)
1015 德才论 (25)(25 分)提问 宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子, ...
- PAT-乙级-1015. 德才论 (25)
1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Li 宋代史学家司马光在<资治通鉴&g ...
- PAT 乙级 1015
题目 题目地址:PAT 乙级 1015 题解 常规题,难点在于理清楚排序规则,通过比较简洁的方式进行编码: 在这里我选择使用vector进行存储,并使用sort方法排序,因为本题不是简单按照大小排序, ...
- PATB 1015. 德才论 (25)
1015. 德才论 (25) 比较函数折腾好久,最后还因为cout,printf的区别而超时,超时是因为cout输出效率低. 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 ...
- PAT——乙级1015/甲级1062:德才论
这两个题是一模一样的 1015 德才论 (25 point(s)) 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德 ...
随机推荐
- new char[]和new char()的区别
new char[1];分配一块连续的内存,也就是一个数组,里面有1个元素new char(1);分配一块内存,有一个元素,该元素被初始化为1
- Installing OpenCV 2.4.10 in Ubuntu 12.04 LTS
转自 http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/ EDIT: I published a ...
- iOS单例模式
单例模式用于当一个类只能有一个实例的时候, 通常情况下这个“单例”代表的是某一个物理设备比如打印机,或是某种不可以有多个实例同时存在的虚拟资源或是系统属性比如一个程序的某个引擎或是数据.用单例模式加以 ...
- mouseenter(fn)和mouseleave、mouseover和mouseout的的区别
$('.box1').mouseenter(function(){//穿入事件mouseenter $(this).css('background','red'); }).mouseleave(fun ...
- 概率dp入门
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...
- 微信小店分类ID列表
一级分类 { , "errmsg": "ok", "cate_list": [ { ", "name": &q ...
- APP源码集中打包大放送!十一个千万级别APP源码随意处置!
小伙伴们还在一个一个苦苦寻找各类APP源码吗?此贴集中打包最常用APP的源码,你想得到的APP,这里都有! 想做商城?这里有天猫! 想做同城服务?这里有大众点评! 想做外卖?这里有饿了么! 想做视频? ...
- WPF中model属性即时改变
新建一个model作为说明即可,以便查阅. 添加引用:using System.ComponentModel ; public class Test:INotifyPropertyChanged { ...
- Power-BI绿色开发平台
- 删除SSMS中保存的帐户信息
通常我们在对象资源管理器中连接服务器时,会发现在服务器名称下保存有之前的实例信息.随着连接增多,要找某个连接还得费劲.sql2012:此时可以删除C:\Users\Administrator\AppD ...