C++STL算法 is_sorted比较学生成绩
2021/7/17 11:05:42
本文主要是介绍C++STL算法 is_sorted比较学生成绩,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
总分和裸分其实没差那么多,也就是100一里
#include<iostream> #include<cstdlib> #include<vector> #include<algorithm> using namespace std; enum AddColumn { AddType_A = 5,// 班级干部 AddType_B = 50,// 领导亲戚 AddType_C = 3,// 校队队员 AddType_D = -15,// 违规违纪 AddType_E = 0// 一般选手 }; class Stu { public: typedef int index; explicit Stu(index point , AddColumn add):point(point), add(add) { index temp= point + add; if (temp > 100)temp = 100; if (temp < 0)temp = -1; this->total = temp; } bool operator<(Stu s) { return this->total < s.total; } friend bool compareStu(Stu s1, Stu s2); operator index() { return this->total; } //index getpoint() { return this->point; } private: index point;//裸分 AddColumn add;// 加分 index total;// 总分 }; bool compareStu(Stu s1, Stu s2) { return s1.point < s2.point; } int main() { vector<Stu> stuVec; stuVec.push_back(Stu(99, AddType_E)); stuVec.push_back(Stu(48, AddType_B)); stuVec.push_back(Stu(100, AddType_D)); stuVec.push_back(Stu(81, AddType_C)); sort(stuVec.begin(), stuVec.end(),less<Stu::index>());// 总分从小到大排列 for_each(stuVec.begin(), stuVec.end(), [](Stu s) {cout << Stu::index(s) << "\t"; }); cout << endl; bool result = is_sorted(stuVec.begin(), stuVec.end(), compareStu); if (result) { cout << "NB的人在NA和NC之间徘徊" << endl; } else { cout << "公平一直是相对的" << endl; } //for_each(stuVec.begin(), stuVec.end(), [](Stu s) {cout << s.getpoint() << "\t"; }); return EXIT_SUCCESS; }
这篇关于C++STL算法 is_sorted比较学生成绩的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-29易优CMS安装常见问题汇总-icode9专业技术文章分享
- 2024-06-28易优新手必读安装教程-icode9专业技术文章分享
- 2024-06-28忘记eyoucms后台密码怎么办?-icode9专业技术文章分享
- 2024-06-26终极指南:Scrum中如何设置需求优先级
- 2024-06-26AI大模型企业应用实战(25)-为Langchain Agent添加记忆功能
- 2024-06-26小白家庭 nas 搭建方案-icode9专业技术文章分享
- 2024-06-23AI大模型企业应用实战(14)-langchain的Embedding
- 2024-06-23AI大模型企业应用实战(15)-langchain核心组件
- 2024-06-23AI大模型企业应用实战(16)-langchain核心组件
- 2024-06-23AI 大模型企业应用实战(06)-初识LangChain