--------【STL】
文章平均质量分 70
STL
Dream-chasing ant
鄙人水平不高,建立博客初心只是想留一份回忆给自己。
展开
-
algorithm头文件下的常用函数
文章目录max()、min()和abs()swap()reverse()next_premutation()fill()sort()基本数据类型数组的排序结构体数组的排序容器的排序lower_bound()和upper_bound()max_element()、min_elementmax()、min()和abs()max(x,y)、min(x,y)分别访问x和y的最大值和最小值,且参数必须是两个。如果想返回三个数x、y、z的最大值,可以使用max(x,max(y,z))的写法.abs(x)返回x的原创 2020-08-18 11:14:53 · 197 阅读 · 0 评论 -
pair用法小结
文章目录定义初始化临时构建元素的访问常用函数比较操作数常见用途定义想要将两个元素绑在一起作为合成元素,又不想定义结构体,用pair.#include<map>//头文件pair<typename1,typename2> name;//定义初始化#include<cstdio>#include<iostream>#include<map>using namespace std;pair<string,int> p原创 2020-08-17 22:55:45 · 296 阅读 · 0 评论 -
stack用法小结
文章目录定义容器内元素访问常用函数push()top()pop()empty()size()常见用途定义翻译为栈,是实现一个后进先出的容器stack<typename> name;容器内元素访问用top()来访问栈顶元素常用函数push()push(x)将x入栈,O(1)#include<cstdio>#include<iostream>#include<stack>using namespace std;stack&l原创 2020-08-17 22:37:16 · 198 阅读 · 0 评论 -
priority_queue用法小结
文章目录定义容器内元素的访问常用函数push()top()pop()empty()size()优先级设置基本数据类型的设置结构体的优先级设置定义又称优先队列,底层用堆实现。队首元素一定是优先级最高的那一个。写法与其他STL相同priority_queue<typename> name;容器内元素的访问和队列不同,优先队列没有front()、back()函数,而是只能通过top()函数来访问队首元素#include<cstdio>#include<ios原创 2020-08-17 22:13:38 · 137 阅读 · 0 评论 -
queue用法小结
文章目录定义容器内元素的访问常用函数push()front()、back()pop()empty()size()定义队列,实现一个先进先出的容器queue<typename> name;容器内元素的访问由于是一个先进先出的容器,所以只能通过front()来访问队首元素,或者通过back()来访问队尾元素#include<cstdio>#include<iostream>#include<queue>using namespace s原创 2020-08-17 21:42:12 · 252 阅读 · 0 评论 -
map用法小结
文章目录定义map容器内元素的访问通过下标访问通过迭代器访问常用函数find()erase()size()clear()定义map为映射可以将任何基本类型(包括STL容器)映射到任何基本类型(包括STL容器),也可以建立string到int的类型map<typename1,typename2> mp;map容器内元素的访问通过下标访问map中键值是唯一的map以键从小到大自动排序it->first来访问键,it->second来访问值通过迭代器访问常用原创 2020-08-17 21:20:13 · 139 阅读 · 0 评论 -
string用法小结
文章目录定义访问通过下标通过迭代器访问常用函数operator+=compare operatorlength()/size()insert()erase()clear()substr()string::nposfind()replace()定义string只能用cin、cout,除非强制转换string s="abc";访问通过下标#include<cstdio>#include<iostream>using namespace std;string s="原创 2020-08-17 20:28:22 · 97 阅读 · 0 评论 -
set用法小结
文章目录概念set的定义set容器内元素的访问倒序遍历所有元素set常用函数insert()find()erase()size()clear()lower_bound(key_value)upper_bound(key_value)empty()swap()概念是一个内部自动有序且不含重复元素的容器C++ 11,还有unordered_set,去重但不排序set的定义set<typename> name;set<int> name;set<node>原创 2020-08-17 16:25:12 · 199 阅读 · 0 评论 -
vector用法小结
文章目录概念定义容器内元素的访问通过下标访问通过迭代器访问常用函数push_backpop_back()size()clear()insert()erase()概念vector像一个变长的数组.常见用途:(1)存储数据(2)用临接表存储图定义vector<typename> name;struct node{ int x,y;};vector<node> name;vector<int> vi[100];容器内元素的访问通过下标访问原创 2020-08-17 14:24:10 · 193 阅读 · 0 评论 -
Lifeform Detector
传送门这道题跟匹配括号类似,是对栈的简单应用还要注意一点的是,if(!q.empty()),else 对应的是空。而不是if(q.top()==‘a’)对应#include<cstdio>#include<iostream>#include<stack>using namespace std;stack<char> q;string ...原创 2020-03-09 21:43:40 · 84 阅读 · 0 评论 -
STL-map
map头文件格式map容器内元素的访问find()函数erase()函数size()函数rbegin()函数操作头文件#include<map>格式map<ll,int> q;map容器内元素的访问(1)map中的键是唯一的(2)通过迭代器访问map<ll,int>::iterator it访问键it->first访问值it...原创 2020-01-16 11:53:32 · 106 阅读 · 0 评论 -
c++常用的大小写转换
文章目录stringchar数组string如果是string 函数的话就用#include<algorithm>头文件下的函数transform(a.begin(),a.end(),a.begin(),::tolower)//是大写变小写transform(s.begin(),s.end(),s.begin(),::tolower)//小写变大写#include<...原创 2020-03-01 17:11:19 · 287 阅读 · 0 评论