![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
STL
Soaring丶
这个作者很懒,什么都没留下…
展开
-
STL综合案例(学校演讲比赛)
学校演讲比赛介绍:1)某市举行一场演讲比赛( speech_contest ),共有24个人参加。比赛共三轮,前两轮为淘汰赛,第三轮为决赛。2)比赛方式:分组比赛,每组6个人;选手每次要随机分组,进行比赛;第一轮分为4个小组,每组6个人。比如100-105为一组,106-111为第二组,依次类推,每人分别按照抽签(draw)顺序演讲。当小组演讲完后,淘汰组内排名最后的三个选手,然后继续下一个小组的比赛。第二轮分为2个小组,每组6人。比赛完毕,淘汰组内排名最后的三个选手,然后继续下一个小组的比赛。原创 2021-11-06 10:20:30 · 235 阅读 · 0 评论 -
STL——集合算法(set_intersection、set_union、set_difference)
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<algorithm>#include<functional>//#include<numeric>//算术生成算法的头文件using namespace std;//set_intersection算法 求两个set集合的交集//注意:两个集合必须是有序序列void test01()原创 2021-11-05 21:25:43 · 142 阅读 · 0 评论 -
STL——算数生成算法(accumulate/fill)
#define _CRT_SECURE_NO_WARNINGS#include#include#include#include#include//算术生成算法的头文件using namespace std;//accumulate算法 计算容器元素累计总和void test01(){vector v;v.push_back(10);v.push_back(20);v.push_back(30);//第三个参数是在总和上再加上0int ret=accumulate(v.begin原创 2021-11-05 18:18:16 · 96 阅读 · 0 评论 -
STL——拷贝和替换算法(copy/replace/swap)
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<algorithm>#include<functional>#include<string>using namespace std;//拷贝void test01(){ vector<int> v; v.push_back(10); v.push_back(20);原创 2021-11-05 17:05:18 · 132 阅读 · 0 评论 -
STL——排序算法(merge、sort、random_shuffle、reverse)
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<algorithm>#include<functional>#include<string>#include<ctime>using namespace std;//merge算法 容器元素合并,并存储到另一容器中void test01(){ vector<in原创 2021-11-05 16:40:23 · 111 阅读 · 0 评论 -
STL——查找算法(find/find_if/adjacent_find/binary_search/count)
#define _CRT_SECURE_NO_WARNINGS#include#include#include#include#includeusing namespace std;bool Myprint(int v){return v > 30;}void test01(){vector v;v.push_back(10);v.push_back(20);v.push_back(30);v.push_back(40);v.push_back(50);/*_I原创 2021-11-05 15:30:21 · 142 阅读 · 0 评论 -
STM——遍历算法(for_each、transform)
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<algorithm>#include<functional>using namespace std;struct myPrint{public: myPrint() { a = 0; } void operator()(const int &val) { cout <原创 2021-11-04 21:20:47 · 137 阅读 · 0 评论 -
STL——适配器示例
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<algorithm>#include<functional>#include<vector>#include<string>//第一步:继承binary_function<参数1,参数2,返回类型>struct Myfunc:public binary_funct原创 2021-11-04 19:49:39 · 70 阅读 · 0 评论 -
STL——内建函数对象举例
/*template<class T> bool equal_to<T>//等于template<class T> bool not_equal_to<T>//不等于template<class T> bool greater<T>//大于template<class T> bool greater_equal<T>//大于等于template<class T> bool less<T原创 2021-11-04 15:34:58 · 83 阅读 · 0 评论 -
STL——员工分配案例
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<map>using namespace std;#include<string>#include<ctime>#define SALE_DEPATMENT 1 //销售部门#define DEVELOP_DEPATMENT 2 //研发部门#define FINACIAL_DEPAT原创 2021-11-04 14:20:11 · 78 阅读 · 0 评论 -
STL——set容器
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<set>//multset也是这个头文件#include<algorithm>#include<string>void test(){ set<int>::iterator it; it++; it--; //it + 2;err //双向迭代器}void pri原创 2021-11-04 11:18:59 · 60 阅读 · 0 评论 -
STL——电梯案例
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<list>#include<vector>#include<queue>#include<string>#include<ctime>//抽象人员class Student{public: string name;};//打印人员void print原创 2021-11-03 21:26:19 · 133 阅读 · 0 评论 -
STL——list容器
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<list>#include<vector>#include<algorithm>void printList(const list<int> &mylist){ for (list<int>::const_iterator it = mylist.begin原创 2021-11-03 20:10:52 · 59 阅读 · 0 评论 -
STL——queue容器
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<queue>#include<string>void test01(){ queue<int> q; for (int i = 0; i < 5; i++) { q.push(i + 1); } cout << "front:" << q.front原创 2021-11-03 19:09:21 · 89 阅读 · 0 评论 -
STM——stack容器
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<stack>#include<string>//栈容器,先进后出//存储基础数据类型void test01(){ stack<int> s; s.push(10); s.push(20); s.push(30); s.push(40); s.push(50); //输出栈中原创 2021-11-03 19:08:48 · 66 阅读 · 0 评论 -
STL——打分案例
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<deque>#include<string>#include<algorithm>//算法头文件#include<ctime>using namespace std;//目的:5个学生,10个评委,10个评委的分数去掉最高和最低分,取平均分就是学生的分数//抽象学生cla原创 2021-11-03 18:37:02 · 63 阅读 · 0 评论 -
STL——deque容器
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<deque>using namespace std;void test(){ deque<int>::iterator it; it++; it--; it + 2;}void printDeque(const deque<int> &deq){ for (deque<int>::const_ite原创 2021-11-03 16:22:32 · 51 阅读 · 0 评论 -
STL———vector容器
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<vector>void printVector(const vector<int> &vec){ for (vector<int>::const_iterator it = vec.begin(); it != vec.end(); ++it) { cout << *原创 2021-11-03 15:35:33 · 54 阅读 · 0 评论 -
STL——string容器
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>using namespace std;void test(){ string::iterator it; it++; it--; it + 2;}/*构造函数string();//创建一个空的字符串 例如: string str;string(const string& str);//使用一个string对象初始原创 2021-11-03 14:36:38 · 49 阅读 · 0 评论 -
STL的基本使用示例(STL的helloworld)
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>//容器#include<algorithm>//算法的头文件#include<string>using namespace std;//加入算法的回调函数void MyPrint(int val){ cout << val << " ";}//1.存储基础数据类型void test原创 2021-11-02 22:00:53 · 177 阅读 · 0 评论