首页 技术 正文
技术 2022年11月16日
0 收藏 343 点赞 4,207 浏览 1457 个字

题目链接

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/

欢迎讨论和交流!


相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,994
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,507
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,350
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,845