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 ...
随机推荐
- Asp.Net、API 、MVC、 PUT/DELETE 报405错解决办法
本地put/delete能正常运行,但是部署在服务器就 报webapi method not allowed 405的错误 解决方案就是在Web.config里面加入如下设置: <system. ...
- office常用技巧汇总
1.excel篇 (1)一次选择多行 可以利用SHIFT+鼠标实现,点第一行,按下鼠标,点200行,就能实现1~200行选择了. 总结:就是一直按住shift键,鼠标点击要选择的首行,再点击尾行.
- tkmybatis VS mybatisplus
本文是简单对比了以下官网上的内容 文章目录 TkMybatis Vs MybatisPlus 1.基础CRUD BaseMapper 2.代码生成器 3. 全局主键 Sequence主键 4. 热加载 ...
- C# Newtonsoft.Json.JsonReaderException:“Could not convert string to decimal:
使用Newtonsoft.Json,报以上错误,问题的原因是有"",把“”替换成null: 以前的json: [{"WengvNj":"df5c38c ...
- 硬件笔记之制作MacOS Mojave U盘USB启动安装盘方法
0x00 概述 随着苹果 macOS Mojave 正式版发布,很多使用 Mac 电脑的同学都已升级到最新版了.但如果你对系统有洁癖或原本系统已凌乱不堪,那么可能还是希望能格式化「全新安装 macOS ...
- node、npm、gulp安装
1.先安装node.js ,官网下载地址:https://nodejs.org/en/ 2.安装完node之后,npm自动就安装了.可以直接在visual studio code 通过命令查看 nod ...
- 小程序上传图片功能 uploadFile:fail Read error:ssl=0xa738d808:I/O error during system call,Connection reset by peer
由于纯网页上传图片小程序会闪退,就采用了小程序原生的上传功能wx.uploadfile 处理流程: 1.网页需要跳转到小程序 需要引用 <script src='https://res.wx.q ...
- 微信页面script标签添加crossorigin=“anonymous”导致页面加载失败
公司一个微信企业号项目,突然出现页面数据加载失败,页面报错信息如下 意思是前端向服务端发送跨域资源请求访问这个js文件,但是服务端并不同意,所以服务端拒绝访问这个地址. 后来发现将crossorigi ...
- Laravel API跨域访问的实现步骤
本篇文章给大家带来的内容是关于Laravel API跨域访问的实现步骤,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 服务器A请求服务器B的接口,那么一般会出现跨域问题. 1 XML ...
- Java自学-I/O 字节流
Java 字节流 InputStream OutputStream InputStream字节输入流 OutputStream字节输出流 用于以字节的形式读取和写入数据 步骤 1 : ASCII码 所 ...