常用STL的常见用法
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#pragma GCC optimize(2)
//#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <algorithm>
#include <iostream>
#include<fstream>
#include<sstream>
#include<iterator>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set> //freopen("C:\\Users\\CAI\\Desktop\\Test\\in.txt", "r", stdin);
//freopen("C:\\Users\\CAI\\Desktop\\Test\\out.txt", "w", stdout);
//freopen("C:\\Users\\CAI\\Desktop\\Test\\tout.txt", "w", stdout); using namespace std;
typedef double dou;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii; #define pai acos(-1.0)
#define M 1000500
#define inf 0x3f3f3f3f
#define mod 1000000007
#define IN inline
#define W(a) while(a)
#define lowbit(a) a&(-a)
#define left k<<1
#define right k<<1|1
#define lson L, mid, left
#define rson mid + 1, R, right
#define ms(a,b) memset(a,b,sizeof(a))
#define Abs(a) (a ^ (a >> 31)) - (a >> 31)
#define random(a,b) (rand()%(b+1-a)+a)
#define false_stdio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) int main() {
false_stdio; return ; }
//string常用
void String()
{
string str;
str.substr(起点下标,长度(包含起点))//复制子串
str.resize(长度, 填充);//重新设置大小
str.empty();//检查是否为空,空则返回true
str.size();//获取字符串大小
str.find(字符或字符串, 起点下标)//找到返回匹配的第一个字符的下标,找不到则返回string::npos
str.insert(str.begin(),字符串或字符串) //插入字符串在起点前面
} //map常用
void Map_()
{
map<typedef, typedef>Map;
Map.erase(key);//删除key的元素
Map.count(元素);//如果有该元素则返回1,没有则返回0,没有则返回map.end()
Map.find(元素);//返回该元素下标,没有则返回map.end()
iter->first;//代表key
iter->second;//代表元素
} //vector常用
void Vector_()
{
vector<int>num;
num.push_back();//添加到尾部
num.erase(num.begin(), num.begin()+n);//删除0~n-1
num.insert(num.begin() + id, x);//插入x在i第id位的前面
num.clear();//清空
} //queue常用
void queue_()
{
queue<int>num;
num.push();//添加到队尾
num.pop();//弹出队头
num.front();//返回队头元素
num.back();//返回队尾元素
num.empty();////检查是否为空,空则返回true
} //Set常用
void Set()
{
set<int>num;
num.upper_bound();//返回大于某个值元素的迭代器
num.lower_bound();// 返回指向大于(或等于)某值的第一个元素的迭代器
num.insert();// 在集合中插入元素
num.find();// 返回一个指向被查找到元素的迭代器
} void priority_queue_() {
struct Data {
int a, b;
//重载小于号
bool operator <(const Data& t)const {
return a < t.a;//降序
return a > t.a;//升序
}
};
priority_queue<Data, vector<Data>, less<Data>>num;//最大堆
priority_queue<Data, vector<Data>, greater<Data>>num;//最小堆
} void Daily()
{
abs();//整数求绝对值
fabs();//浮点数求绝对值 reverse(num.begin(), num.end());//反转字符串或者数组
vector<int>::iterator iter = num.begin();//迭代器 //字符串转换和串流的反复利用
int num;
string str;
stringstream ss;
ss << str;
ss >> num;
ss.str("");
ss.clear();
}
常用STL的常见用法的更多相关文章
- STL stack 常见用法详解
<算法笔记>学习笔记 stack 常见用法详解 stack翻译为栈,是STL中实现的一个后进先出的容器.' 1.stack的定义 //要使用stack,应先添加头文件#include &l ...
- STL priority_queue 常见用法详解
<算法笔记>学习笔记 priority_queue 常见用法详解 //priority_queue又称优先队列,其底层时用堆来实现的. //在优先队列中,队首元素一定是当前队列中优先级最高 ...
- STL map 常见用法详解
<算法笔记>学习笔记 map 常见用法详解 map翻译为映射,也是常用的STL容器 map可以将任何基本类型(包括STL容器)映射到任何基本类型(包括STL容器) 1. map 的定义 / ...
- STL set 常见用法详解
<算法笔记>学习笔记 set 常见用法详解 set是一个内部自动有序且不含重复元素的容器 1. set 的定义 //单独定义一个set set<typename> name: ...
- STL vector常见用法详解
<算法笔记>中摘取 vector常见用法详解 1. vector的定义 vector<typename> name; //typename可以是任何基本类型,例如int, do ...
- STL pair 常见用法详解
<算法笔记>学习笔记 pair 常见用法详解 //pair是一个很实用的"小玩意",当想要将两个元素绑在一起作为一个合成元素, //又不想因此定义结构体时,使用pair ...
- STL queue 常见用法详解
<算法笔记>学习笔记 queue 常见用法详解 queue翻译为队列,在STL中主要则是实现了一个先进先出的容器. 1. queue 的定义 //要使用queue,应先添加头文件#incl ...
- STL string 常见用法详解
string 常见用法详解 1. string 的定义 //定义string的方式跟基本数据类型相同,只需要在string后跟上变量名即可 string str; //如果要初始化,可以直接给stri ...
- C++标准模板库(STL)——queue常见用法详解
queue的定义 queue<typename> name; queue容器内元素的访问 由于队列本身就是一种先进先出的限制性数据结构,因此在STL中只能通过front()来访问队首元素, ...
随机推荐
- P1013 数素数
转跳点:
- VNC连接桌面
1.#yum -y install vnc *vnc-server* 2.修改VNCServer主配置文件 #vim /etc/sysconfig/vncservers 复制最后两行并去掉行首注释符, ...
- bzoj 1832: [AHOI2008]聚会
良心题2333 三个点两两求一遍就行,最小肯定是在某2个点的lca处,(肯定让第三个人去找2个人,不能让2个人一起去找第三个人233) #include<bits/stdc++.h> #d ...
- Canvas基本定义
Android中使用图形处理引擎,2D部分是android SDK内部自己提供,3D部分是用Open GL ES 1.0.今天我们主要要了解的是2D相关的 大部分2D使用的api都在android.g ...
- 全面掌握Nginx配置+快速搭建高可用架构 一 开启status页面检测服务状态
输入命令Nginx -V 打开conf.d/default.conf 配置模块,配置位置在server或者location 配置完成后测试语法正确 nginx -tc /etc/nginx/nginx ...
- SpringMVC错误,商品添加信息HTTP Status 400 – Bad Request
记录一个自己在做商品信息显示与传递数据的时候出现的错误, HTTP Status 400 – Bad Request Type Status Report Description The server ...
- consul配置
参考:https://blog.csdn.net/achenyuan/article/details/80389410 gcp: consul安装目录:/usr/local/bin/consul co ...
- VSFTP 连接时425 Security: Bad IP connecting.报错-----解决方法
当登录FTP时候出现这个报错时.是因为PASV模式的安全检查是开启的(默认是开启的) ftp> ls227 Entering Passive Mode (172,16,101,33,35,58 ...
- 寒假day21
标签模块报了一些错误,暂时没有找出原因.刷了一些面试题
- 翻译SSD论文(Single Shot MultiBox Detector)
转自http://lib.csdn.net/article/deeplearning/53059 作者:Ai_Smith 本文翻译而来,如有侵权,请联系博主删除.未经博主允许,请勿转载.每晚泡脚,闲来 ...