题目链接

https://pintia.cn/problem-sets/994805260223102976/problems/994805307551629312

题解

思路比较简单,核心就是定义一个学生的排序规则:将考生分为4类(德和才分数都低于L的直接淘汰),先比较考生的类型,再比较分数或者准考证号,其中分数都是降序、准考证号是升序。

淘汰直接在获取考生信息时进行;分类由Student构造函数实现;考生排序由stuCmp实现。

// PAT BasicLevel 1015
// https://pintia.cn/problem-sets/994805260223102976/problems/994805307551629312 #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std; int N, L, H, M;
class Student
{
public:
string id;
int de;
int cai;
int type;
Student(string id,int de,int cai){
this->id=id;this->de=de;this->cai=cai;
if (de >= H && cai >= H){//才德全尽
this->type=3;
}else if(de>=H&&cai<H){//德胜才
this->type = 2;
}else if(de<H&&cai<H&&de>=cai){//“才德兼亡”但尚有“德胜才”者
this->type = 1;
}else{//达到最低线L
this->type = 0;
}
}
void print(){
cout << id << ' ' << de << ' ' << cai << endl;
}
}; bool stuCmp(Student&, Student&); int main()
{
// 考生数 最低录取线 优先录取线
cin >> N >> L >> H; // 获取考生信息
vector<Student> stuVec;
string id;int de;int cai;
for(int i=0;i<N;i++){
cin >> id >> de >> cai;
// 只存储cai和de不低于L的
if (de >= L && cai >= L){
stuVec.push_back(Student(id, de, cai));
M++;
}
} // 学生排序
sort(stuVec.begin(),stuVec.end(),stuCmp); // 输出结果
cout << M << endl;
for (vector<Student>::iterator it = stuVec.begin(); it != stuVec.end(); ++it){
it->print();
} //system("pause");
return 0;
} bool stuCmp(Student &s1, Student &s2)
{
if(s1.type==s2.type){// 同种type,比较总分
if (s1.cai + s1.de == s2.cai + s2.de){
if(s1.de==s2.de){
// id升序输出,其他都是降序输出的
return s1.id < s2.id;
}else{
return s1.de>s2.de;
}
}else{
return s1.cai + s1.de > s2.cai + s2.de;
}
}else{
return s1.type>s2.type;
}
}

作者:@臭咸鱼

转载请注明出处:https://www.cnblogs.com/chouxianyu/

欢迎讨论和交流!


最新文章

  1. 开发常用之在webstorm中使用cmd
  2. Openstack的计算节点的nova-network异常中止及实例无法删除排错过程
  3. 从Wireshark监听的数据中提取需要的数据
  4. Spring笔记(四)SpingAOP
  5. O-C相关-10-动态类型检查
  6. [Mugeda HTML5技术教程之11]Mugeda API简介
  7. LESSCSS
  8. springmvc 关于controller的字符编码
  9. 使用微软URLRewriter.dll的url实现任意后缀名重写
  10. &#39;boost/iterator/iterator_adaptor.hpp&#39; file not found之xcode生成时报错的解决方案
  11. MySQL数据库引擎MyISAM和InnoDB的区别介绍
  12. JHipster - Generate your Spring Boot + Angular/React applications!
  13. 52ABP视频学习
  14. realloc 使用详解(分析realloc invalid pointer、指针无效等错误)【转】
  15. linux 启动自动运行
  16. 创建Springmvc项目时,特殊拦截器失效情况的原因及解决办法
  17. android DrawerLayout 侧边栏实现
  18. Error:Cause: org/gradle/api/publication/maven/internal/DefaultMavenFactory 解决办法
  19. Python下载网页图片
  20. Apache Drupal URL重写【转】

热门文章

  1. 冒泡排序到demo
  2. matlab之编写函数m文件计算排列组合Cnm
  3. 【计算机视觉】【并行计算与CUDA开发】GPU硬解码---DXVA
  4. windows 3种方式运行exe文件
  5. MySQL_数据查询
  6. C++命名建议
  7. iis实现方向代理
  8. Spring之一:IoC容器体系结构
  9. C++类的对象和类的指针的区别
  10. python中的类变量和对象变量,以及传值传引用的探究