pair node stack vector string priority_queue
map
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<char,string> mp;
signed main() {
ios::sync_with_stdio();
mp[''] = "";mp[''] = "";mp[''] = "";
mp['A'] = ""; map<char,string> :: iterator it;
for(it = mp.begin(); it != mp.end();it++)
cout << it->first << " " << it->second << endl;
cout << "倒序遍历:\n";
for(auto t = --mp.end();;t--){
cout << t->first << " " << t->second << endl;
if(t == mp.begin()) break;
}
cout << "auto的遍历:\n";
for(auto itt : mp)
cout << itt.first << " " << itt.second << endl; return ;
}
vector
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v;
int main(){
if(v.empty())
puts("v is empty");
for(int i = ; i < ; i ++)
v.push_back(i);
cout << v.size() << endl;
v.insert(v.begin() + , );//在第10个元素前面插入10
v.push_back();//尾部插入10
for(int i = ; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
v.erase(v.begin() + );//删除第10个
v.pop_back();//删除末尾
for(int i = ; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
reverse(v.begin(),v.end());//反转
for(int i = ; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
sort(v.begin(),v.end());
for(int i = ; i < v.size(); i++)
cout << v[i] << " ";
return ;
}
v [ n ]
返回 v 中位置为 n 的元素。
push_back() 在数组的最后添加一个数据
pop_back() 去掉数组的最后一个数据
begin() 得到数组头的指针
end() 得到数组的最后一个单元+1的指针
empty() 判断vector是否为空
swap() 与另一个vector交换数据
string
| 长度 | str.length(), str.size() |
|---|---|
| 比较 | str1.compare(str2) |
| 查找 | pos = str1.find(str2) |
| 连接 | str1 += str2 |
| 插入 | str1.insert(pos,str2) |
| 替换 | str1.replace(pos,n,str2) |
| 删除 | str1.erase(pos,len) |
| 清除 | str.clear() |
| 判空 | str.empty() |
| 反转 | reverse(s.begin(),s.end()) |
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
string str1,str2,str3;
str1 = "Hello";
str2 = "World";
cout << str1.insert(2,str2) << endl;
cout << str1 << endl;
cout << str1.replace(0,1,str2) << endl;//从下标0开始的1个用str2替换
cout << str3 << endl;
cout << str3.find("World") << endl;
cout << str3.erase(2,3)<< endl;
cout << str3 << endl;
reverse(str3.begin(),str3.end());
cout << str3 << endl;
}
vector 和string基本差不多
priority_queue
建立的时间复杂度O(n)
插入删除时间复杂度O(log n)
升序
priority_queue<int,vector<int>,greater<int>> que;
降序
priority_queue<int> que;
与普通队列
同:在队尾插入,队头删除
异:队列中最大元素总是在队头(这也就是说,出队列不是按照先进先出,而是按照元素大小,从大到小出去)
pair node stack vector string priority_queue的更多相关文章
- c++ StrVec等效vector(string)的类
c++ StrVec等效vector<string>的类 知识点 静态成员变量要在类外定义和初始化 allocator类是使用和uninitialized_copy的配合使用,实现stri ...
- C++ Split string into vector<string> by space
在C++中,我们有时候需要拆分字符串,比如字符串string str = "dog cat cat dog"想以空格区分拆成四个单词,Java中实在太方便了,直接String[] ...
- 单独删除std::vector <std::vector<string> > 的所有元素
下面为测试代码: 1.创建 std::vector< std::vector<string> > vc2; 2.初始化 std::vector<string> vc ...
- 给jdk写注释系列之jdk1.6容器(10)-Stack&Vector源码解析
前面我们已经接触过几种数据结构了,有数组.链表.Hash表.红黑树(二叉查询树),今天再来看另外一种数据结构:栈. 什么是栈呢,我就不找它具体的定义了,直接举个例子,栈就相当于一个很窄的木桶 ...
- 编写程序,将来自文件中的行保存在一个vector<string>,然后使用一个istringstream 从vector中读取数据,每次读一个单词
#include<fstream> #include <vector> #include<string> #include<iostream> #inc ...
- vector(char*)和vector(string)
vector<char*> ch; vector<string> str; for(int i=0;i<5;i++) { char *c=fun1();//通过这个语句产 ...
- Effective STL 学习笔记: 多用 vector & string
Effective STL 学习笔记: 多用 vector & string 如果可能的话, 尽量避免自己去写动态分配的数组,转而使用 vector 和 string . 原书作者唯一想到的一 ...
- PKU 1035 Spell checker(Vector+String应用)
题目大意:原题链接 1输入一个字符串,如果字典中存在该字符串,直接输出,否则; 2.删除,替换,或插入一个字母.如果使得输入字符串==字典中已经有的单词,输出该单词,否则. 3.直接输入下一个字符串, ...
- C++ Stack 与String
// ConsoleApplication1.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include "pch.h" ...
随机推荐
- python-调用自己写的函数
在同一个目录下的话,直接在代码里添加即可,下面的例子. 同一个目录下有以下: aaa.py ccc.py ddd.py 想在ddd.py里用aaa.py里的函数,就在ddd.py里面开关位置添加 ...
- JS-ES6语法运用
import导入模块,js的模块化开发 浏览器使用ES6模块化语法(使用module时js代码自动运行严格模式): <script type="module" src=&qu ...
- vue中的金额格式0.00 和 后台返回时间格式带T调整正常格式
<template> <div class="consumption"> <p>{{payTime|Time}}</p> <p ...
- VS2015生成代码图
熟悉代码调用流程,可以在调试结束前显示代码图,操作位置: 比如开源的caffe_ocr的代码图:
- 2019冬季PAT甲级第一题
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ][]; ][]; ]; string ...
- jq的 on 事件委托 导致多次执行问题
解除 这个元素 在 父级上的 click 事件委托$(msg.fatherDiv).off('click','.fangdaimg_fn2'); click事件$('.fangdaimg_fn2'). ...
- mvc 上传文件 HTTP 错误 404.13 - Not Found 请求筛选模块被配置为拒绝超过请求内容长度的请求。 maxRequestLength与 maxReceivedMessageSize 和 maxAllowedContentL区别
具体的错误信息如下: 在线上遇到了文件上传问题,在测试环境试了好久都没有发现问题到底出在哪里,以为是服务器做了各种限制,然后一点思绪都没有.最后,尝试将线上的代码包拷贝一份,在测试环境运行,刚开始的时 ...
- 详解Django中Request对象的相关用法
原文链接:http://www.jb51.net/article/69624.htm 1.从Request对象中获取数据 我们在第三章讲述View的函数时已经介绍过HttpRequest对象了,但当时 ...
- Cosmetic Bottles-Cosmetic Packaging Purpose: 5 Things
Packaging in the cosmetics industry is based on in-depth research. And how it helps to win the edge ...
- opencv:绘制图像直方图
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...