PATA1062 Talent and Virtue
- 技术要点就是,一个是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的更多相关文章
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)
1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vecto ...
- 1062.Talent and Virtue
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
- 1062 Talent and Virtue (25 分)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- PAT 1062 Talent and Virtue[难]
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- PAT 1062 Talent and Virtue
#include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #i ...
- pat1062. Talent and Virtue (25)
1062. Talent and Virtue (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Li Abou ...
- 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 ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
随机推荐
- go-gin-api 路由中间件 - 签名验证(七)
概览 首先同步下项目概况: 上篇文章分享了,路由中间件 - Jaeger 链路追踪(实战篇),文章反响真是出乎意料, 「Go中国」 公众号也转发了,有很多朋友加我好友交流,直呼我大神,其实我哪是什么大 ...
- 用siege测试接口高并发
siege -c 255 -r 2555 "http://10.1.1.6:3001/decode POST <./api.json" -t 100s
- mysql中的回表查询与索引覆盖
了解一下MySQL中的回表查询与索引覆盖. 回表查询 要说回表查询,先要从InnoDB的索引实现说起.InnoDB有两大类索引,一类是聚集索引(Clustered Index),一类是普通索引(Sec ...
- Windows下使用grep命令
一.可供选择的工具列表: Grep for Windows – 轻量级选项 GNU utilities for Win32 – 本地港口 Cash – 重量轻,建于Node.js之上 Cygwin – ...
- EF core的原生SQL查询以及用EF core进行分页查询遇到的问题
在用.net core进行数据库访问,需要处理一些比较复杂的查询,就不得不用原生的SQL查询了,然而EF Core 和EF6 的原生sql查询存在很大的差异. 在EF6中我们用SqlQuery和Exe ...
- Haskell路线
@ 知乎 @ <I wish i have learned haskell> ———— 包括: Ranks, forall, Monad/CPS, monadic parser, FFI ...
- Web Api 模型绑定 一
[https://docs.microsoft.com/zh-cn/aspnet/core/web-api/?view=aspnetcore-2.2]1.模型绑定 简单模型绑定针对简单类型(如stri ...
- ES6 Promise对象(七)
一.Promise介绍1.Promise简单说就是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步操作)的结果2.Promise可以将异步操作以同步操作的流程表达出来,避免了层层嵌套的回调函 ...
- 小程序自定义tabbar custom-tab-bar 6s出不来解决方案,cover-view不兼容
1.从微信小程序的官网扣下来的demo,实际测试中,发现6s ios10 系统不兼容,里面的内容出不来 <cover-view class="tab-bar"> < ...
- 基于 ECharts 封装甘特图并实现自动滚屏
项目中需要用到甘特图组件,之前的图表一直基于 EChart 开发,但 EChart 本身没有甘特图组件,需要自行封装 经过一番鏖战,终于完成了... 我在工程中参考 v-chart 封装了一套图表组件 ...