• 技术要点就是,一个是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. laravel框架中Job和事件event的解析

    本篇文章给大家带来的内容是关于laravel框架中Job和事件event的解析,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 在做项目的时候,一直对Job和Event有个疑惑.感觉两 ...

  2. MediaWiki上传文件大小设置

    一.概述 MediaWiki默认最大上传文件大小为2M,碰到文件较大需要修改这个限制,需要改为8M. 二.修改php.ini 使用docker运行的MediaWiki,默认是没有php.ini这个文件 ...

  3. 【09】Jenkins:Pipeline 补充

    写在前面的话 我们在使用普通的构建任务的时候使用了 Sonar 做代码质量管理,也使用了 Publish Over SSH 插件中更新上线,但是我们在 Pipeline 怎么使用他们呢. 如果你没有查 ...

  4. 使用Ueditor上传图片到图片服务器(二)

    上一篇主要写了前端部分如何配置ueditor的上传路径,已经jsp页面中如何使用ueditor的编辑器功能以及如何配置单独的图片上传功能. 这一篇,我分两部分:第一部分是搭建图片服务器以及配置ftp上 ...

  5. 使“Cmder Here”菜单在Tab页开新窗口

    Cmder是一个非常好用的的控制台命令行,我们在实际使用的时候,经常通过如下指令将其注册到右键菜单: Cmder.exe /REGISTER ALL 这样就可以在任意文件夹下快速打开Cmder,并且能 ...

  6. HTML5新标签和CSS伪类

    HTML5提供了很多新的标签,由于HTML5的兼容性比较差,HTML5的标签常用于手机端 <nav> <footer> <section> <header&g ...

  7. [世预赛] 中国vs菲律宾,第一场考验,国足力争三连胜,比分预测:3:0, 2:0,4:1

    7比0大胜关岛,中国国家男子足球队在冲击2022卡塔尔世界杯的征途上收获两连胜,北京时间10月15日20点,中国男足将奔赴巴科洛德,客场挑战菲律宾男足,本场比赛也是中国男足在本次世预赛四十强赛阶段的第 ...

  8. Bootstrap3-导航条

    1. 定义导航条 <!-- 导航条 navbar --> <div class="navbar nav-bar-default"> <ul class ...

  9. 关于两个DIV之间的空白字符

    首先!!!!这个问题应该是去面试前端会经常问到的问题!!! 如,下面这个例子: <!DOCTYPE html> <html lang="zh-CN"> &l ...

  10. 【转载】Gradle学习 第二章:概述

    转载地址:http://ask.android-studio.org/?/article/6 Here is a list of some of Gradle's features.<翻译> ...