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 ...
随机推荐
- 笔记本CPU性能排行
截图如下: 1. 图1 2. 图2 3. 4. 5. 6. 7. 8. 谢谢浏览!
- Prometheus 告警状态了解
Prometheus 告警状态了解 一旦这些警报存储在Alertmanager,它们可能处于以下任何状态: · Inactive:这里什么都没有发生. · Pending:已触发阈值,但未满足告警持续 ...
- 【docker】centos7 上拉取docker镜像,一直拉取不到,报错:Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while w
镜像拉取一直报错: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request cancel ...
- 【须弥SUMERU】分布式安全服务编排实践
一.概要 1.分布式安全服务编排概念 2.须弥(Sumeru)关键实现思路 3.应用场景 二.前言 在笔者看来,安全防御的本质之一是增加攻击者的攻击成本,尤其是时间成本.那么从防御的角度来说,如何尽早 ...
- chrome(谷歌)浏览器字体发虚解决办法
chrome(谷歌浏览器)浏览网页时,字体发虚的解决办法: 1.点击chrome里的 “设置” - 外观 - 字体,改为 微软雅黑,该方法测试无效. 2.将系统字体的pingfang字体卸载,完美解决 ...
- Windows git和cmd代理设置
linux的比较简单,直接修改配置文件即可,这里就不再赘述 设置Git代理 http代理: 临时代理: export http_proxy=http://127.0.0.1:7777 export h ...
- C# 调用TRIO控制器ActiveX教程
最近项目由于用到上位机与TRIO交互,为了使交互编程方便,使用了TRIO的COM组件.记录一下为方便以后自己使用,同时也方便大家做参考! 组件下载地址(百度云盘):https://pan.baidu. ...
- 2019-11-07 微信小程序入门
1.什么是微信小程序? 小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”,用户扫一扫或者搜一下即可打开应用,体现了“用完即走”的理念,用户不用关心是否安装太多应用的问题.应用将无处不 ...
- js执行上下文栈和变量对象
JavaScript执行上下文栈和变量对象 JS是单线程的语言,执行顺序肯定是顺序执行,但是JS 引擎并不是一行一行地分析和执行程序,而是一段一段地分析执行,会先进行编译阶段然后才是执行阶段. 例子一 ...
- Java中assert(断言)的使用
Java中assert(断言)的使用 1.Eclipse中默认assert(断言)是关闭,开启方式如下: 简单来说:就是设置一下jvm的参数,参数是-enableassertions或者-ea(推荐) ...