• 技术要点就是,一个是cmp函数的书写,首先应该分清楚排序关系,然后按照顺序依次排下去。
  • 还有这里有一个巧妙点就是,在结构体中加入了类别这个标签。
  • 学会抽象分类解决,排序比较函数cmp本质工作就是比较结构体里面的大小,不应该加入其它。

参考代码:

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std; struct Student {
char sno[10];//存储学号
int score_d;//记录德分
int score_c;//记录才分
int sum;//记录总和
int flag;//记录类别
}stu[100010]; bool cmp(Student a, Student b) {
if (a.flag != b.flag) return a.flag < b.flag;
else if (a.sum != b.sum) return a.sum > b.sum;
else if (a.score_d != b.score_d) return a.score_d > b.score_d;
else return strcmp(a.sno, b.sno) < 0;
}
int main() {
int L,H,N;//L是最低分,H记录优先录取的分数,N记录考生人数
scanf("%d%d%d", &N, &L, &H);
int M = N;//可以录取的人数
for (int i = 0; i < N; i++) {
scanf("%s%d%d", stu[i].sno, &stu[i].score_d, &stu[i].score_c);
stu[i].sum = stu[i].score_c + stu[i].score_d;
if (stu[i].score_c < L || stu[i].score_d < L) {
stu[i].flag = 5;
M--;
}
else if (stu[i].score_d >= H && stu[i].score_c >= H) stu[i].flag = 1;
else if (stu[i].score_d >= H && stu[i].score_c < H) stu[i].flag = 2;
else if (stu[i].score_d >= stu[i].score_c) stu[i].flag = 3;
else stu[i].flag = 4;
} sort(stu, stu + N, cmp);
printf("%d\n", M);
for (int i = 0; i < M; i++) {
printf("%s %d %d\n", stu[i].sno, stu[i].score_d, stu[i].score_c);
} system("pause");
return 0; }

PATA1062 Talent and Virtue的更多相关文章

  1. 1062 Talent and Virtue (25)

    /* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...

  2. PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)

    1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vecto ...

  3. 1062.Talent and Virtue

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  4. 1062 Talent and Virtue (25 分)

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  5. PAT 1062 Talent and Virtue[难]

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  6. PAT 1062 Talent and Virtue

    #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #i ...

  7. pat1062. Talent and Virtue (25)

    1062. Talent and Virtue (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Li Abou ...

  8. 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise

    题目信息 1062. Talent and Virtue (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B About 900 years ago, a Chine ...

  9. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

随机推荐

  1. MySQL job/定时任务/event 学习

    参考文章: https://blog.csdn.net/qq_21108311/article/details/82589850 https://blog.csdn.net/qq_27238185/a ...

  2. kafka原理详解之各种offset和checkpoint

    每一个分区都是一个顺序的.不可变的消息队列,并且可以持续的添加.分区中的消息都被分配了一个序列号,称之为偏移量(offset),在每个分区中此偏移量都是唯一的.一个分区在文件系统里存储为一个文件夹.文 ...

  3. select into 与 insert into select

    1.select into select into 语句把一个表中的数据插入到另一个表中. 不需要创建临时表,在运行过程中自动创建. 基本语法: select * into #table_Name f ...

  4. asp.net web 项目 针对aspx和ashx的 IHttpHandlerFactory 开发

    ASP.NET Framework处理一个Http Request的流程: HttpRequest-->inetinfo.exe-->ASPNET_ISAPI.dll-->ASPNE ...

  5. 北理工机器人队RM视觉组ubuntu必备软件安装指南

    基础软件安装 sudo apt update && sudo apt upgrade sudo apt install git curl vim gcc g++ cmake与make ...

  6. HTML中的音频 视频 的播放代码

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  7. javascript getElementsByClassName扩展函数

    代码: function getElementsByClassName(){ if(!arguments[0]){return []};//未指定任何参数,直接返回 var args=argument ...

  8. Kubernetes学习之pause容器

    根据代码看到,pause容器运行着一个非常简单的进程,它不执行任何功能,一启动就永远把自己阻塞住了, 它的作用就是扮演PID1的角色,并在子进程称为"孤儿进程"的时候,通过调用wa ...

  9. MEDICI仿真NMOS器件晶体管语法笔记

    MEDICI仿真NMOS器件晶体管 TITLE     TMA MEDICI Example 1 - 1.5 Micron N-Channel MOSFET 给本例子取的标题,对实际的模拟无用 COM ...

  10. httpclient解析

    1.HttpClient简介 HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性,它不仅使客户端发送Http请求变得容易,而且也方便开发人员测试接口(基于Http ...