vector的用法

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
bool cmp(int a, int b) {return a < b;
}
int main()
{vector<int> vec;vec.push_back(1); //向后添加一个数for (auto it = vec.begin(); it != vec.end(); it++) { // 指针类型 cout << *it;}vec.push_back(1);vec.push_back(5);vec.push_back(2);//auto == std:: vector<int> :: iterator sort(vec.begin(),vec.end(),cmp);for (auto it =vec.begin(); it != vec.end(); it++){cout << *it;}sort(vec.begin(), vec.end(), less<int>());// 从大到小 sort(vec.begin(), vec.end(), greater<int>());// 从小到大vec.pop_back(); // 弹出后面的数vec.erase(unique(vec.begin(), vec.end()), vec.end()); // 去重vec.reverse(vec.begin(),vec.end());return 0;
}

string的用法

#include<bits/stdc++.h>
#include<iostream>
using namespace std;void Stringsplit(const string& str, const char split, vector<string>& res)
{if (str == "")     return;//在字符串末尾也加入分隔符,方便截取最后一段string strs = str + split;size_t pos = strs.find(split);// 若找不到内容则字符串搜索函数返回 nposwhile (pos != strs.npos){string temp = strs.substr(0, pos);res.push_back(temp);//去掉已分割的字符串,在剩下的字符串中进行分割strs = strs.substr(pos + 1, strs.size());pos = strs.find(split);}
}
// 使用字符串分割
void Stringsplit(const string& str, const string& splits, vector<string>& res)
{if (str == "")     return;//在字符串末尾也加入分隔符,方便截取最后一段string strs = str + splits;size_t pos = strs.find(splits);int step = splits.size();// 若找不到内容则字符串搜索函数返回 nposwhile (pos != strs.npos){string temp = strs.substr(0, pos);res.push_back(temp);//去掉已分割的字符串,在剩下的字符串中进行分割strs = strs.substr(pos + step, strs.size());pos = strs.find(splits);}
}int main()
{string str;cin >> str;cout << str<<endl;for (int i = 0; i < str.size(); i++) {if (str[i] =='1') {cout << i << " " << "为1 ";}}str.substr(0); //截取从0 到 最后的字符串string s = str.substr(1, 4); //截取从位置1以后的4个字符cout << "返回4的小标" << str.find('4')<<endl;//按位置分割// 使用字符串分词vector<string> strList2;string str2("ThisABCisABCaABCtest");Stringsplit(str2, "ABC", strList2);for (auto s : strList2)cout << s << " ";cout << endl;return 0;
}

stack用法

#include<bits/stdc++.h>
#include<iostream>
using namespace std;int main()
{stack<int> st;st.push(1);st.push(2);st.push(5);st.push(8);while (!st.empty()) {cout<< st.top()<<endl; // 查看栈顶元素st.pop();}return 0;
}

queue队列的用法

#include<bits/stdc++.h>
#include<iostream>
using namespace std;int main()
{queue<int> q;q.push(1);q.push(2);q.push(3);q.push(4);while(q.size()) { // 可以用q.empty()cout << q.front();//从第0个开始 先进先出原则q.pop();}return 0;
}

deque双端队列

#include<bits/stdc++.h>
#include<iostream>
using namespace std;int main()
{deque<int> dq;dq.push_front(1);dq.push_back(5);dq.push_front(10);dq.push_back(10);while (!dq.empty()) {cout <<dq.front()<<" ";cout <<dq.back()<<" ";dq.pop_back();dq.pop_front();}return 0;
}

priority_queue<类型,容器,排序(默认小顶堆)>用法

#include<bits/stdc++.h>
#include<iostream>
using namespace std;struct student {int age;int number;bool operator<(const student& ee) const {return age > ee.age; // 从年龄小的到大的 }
};
int main()
{/*priority_queue<int, vector<int>, less<int>> pq; //大顶堆pq.push(1);pq.push(12);while (pq.size()) {cout << pq.top()<<" ";pq.pop();}*/priority_queue<student, vector<student>> pq;student a[3];for (int i = 0; i < 3; ++i) {int age;int number;cin >> age >> number;a[i].age = age, a[i].number = number;pq.push(a[i]);}while (!pq.empty()) {student t = pq.top();cout << t.age << t.number<<endl;pq.pop();}return 0;
}

set用法(以红黑树为基础)

#include<bits/stdc++.h>
#include<iostream>
using namespace std;int main()
{set<int> s;//有排序 s.insert(5);s.insert(4);s.insert(3);for (set<int>::iterator it = s.begin(); it != s.end(); it++){auto j = s.find(5);if (j != s.end()){cout << *j;}}s.erase(3);auto j = s.lower_bound(3); // 大于等于3的第一个数return 0;
}

map用法(以红黑树为基础)

#include<bits/stdc++.h>
#include<iostream>
using namespace std;int main()
{map<int, int> m;int nums[5] = { 1,5,3,4,5 };for (int i = 0; i < 5; i++) {auto it = m.find(4 - nums[i]);if (it != m.end()) {cout<< it->second;break;}m[nums[i]] = i;}m.insert({ 1,2 });m.count(1);//键值的个数m.clear();return 0;
}

unordered_map(基于哈希表)

#include<bits/stdc++.h>
#include<iostream>
#include<unordered_map>
using namespace std;int main()
{unordered_map<int,int> m;int nums[5] = { 1,5,3,4,5 };for (int i = 0; i < 5; i++) {auto it = m.find(4 - nums[i]);if (it != m.end()) {cout<< it->second;break;}m[nums[i]] = i;}m.insert({ 1,2 });cout <<m.count(1);//键值的个数m.clear();return 0;
}

unordered_set(基于哈希表)

#include<bits/stdc++.h>
#include<iostream>
#include<unordered_map>
#include<unordered_set>
using namespace std;int main()
{unordered_set<int> s;//查看重复数字int nums[] = {1,3,5,4,4};for(int i = 0; i < 5; i++) {if (s.find(nums[i]) != s.end()) {cout << "找到重复的数字了数字为:" << nums[i] << endl;}s.insert(nums[i]);}return 0;
}

C++常见的SML用法 ACM 必备相关推荐

  1. python函数和方法的入参格式有哪些_Python函数的参数常见分类与用法实例详解

    本文实例讲述了Python函数的参数常见分类与用法.分享给大家供大家参考,具体如下: 1.形参与实参是什么? 形参(形式参数):指的是 在定义函数时,括号内定义的参数,形参其实就是变量名 实参(实际参 ...

  2. php常用操作数组函数,PHP常见数组函数用法小结

    本文实例讲述了PHP常见数组函数用法.分享给大家供大家参考,具体如下: 1.array array_merge(array $array1 [, array  $array2 [, $array]]) ...

  3. 英语常见介词错误用法,你有犯过吗?

    英语常见介词错误用法,你有犯过吗? 1:错:come to here. 对:come here. 过来. here ,there,home之类的副词,前面不用介词in ,at,(但可以加from,比如 ...

  4. MySQL 性能优化:8 种常见 SQL 错误用法!

    声明:转载自 MySQL 性能优化:8 种常见 SQL 错误用法! 1.LIMIT 语句 分页查询是最常用的场景之一,但也通常也是最容易出问题的地方.比如对于下面简单的语句,一般 DBA 想到的办法是 ...

  5. 网络工具nc的常见功能和用法

    文章目录 前言 nc netcat ncat nc的用法 测试udp端口是否可用 端口扫描 一对一聊天 传输文件 端口转发 总结 前言 nc 是一个Linux环境下常用的工具命令,可以用来帮助开发者查 ...

  6. php md5加密(并小写),PHP常见加密函数用法示例【crypt与md5】

    本文实例讲述了PHP常见加密函数用法.分享给大家供大家参考,具体如下: 1.crypt()函数 crypt()函数用于返回使用DES.Blowfish或MD5算法加密过后的字符串,crypt(str, ...

  7. linux常见命令---深度学习炼丹炉必备---更新中

    目录 linux常见命令---深度学习炼丹炉必备---更新中 1.修改环境变量 2.查看当前conda环境 3.如果执行conda activate ***出现问题时需要初始化shell 4.查看当前 ...

  8. 护士常用计算机,临床护理中常见数值一览表,护士必备哦!

    原标题:临床护理中常见数值一览表,护士必备哦! 1.三查七对的内容? 答:三查:操作前,操作中,操作后 七对:对姓名,床号,药名,浓度,剂量,时间,方法. 2.吸氧时设有"四防"的 ...

  9. 常见Shell命令用法总结

    2019独角兽企业重金招聘Python工程师标准>>> 常见命令用法总结 -----  目录:  --- 关于grep的总结   关于egrep的总结   关于tr的总结  关于so ...

最新文章

  1. linux系统桌面缺色,红旗系统如何用?
  2. 浅谈Oracle Online redo log
  3. fields在php中,phpmysqli_num_fields函数怎么用
  4. pythonpip安装与使用_Python pip 安装使用与问题
  5. Python编程习惯
  6. vc6 设置静态文本框透明_微信还能这么玩?半透明的微信背景主题用起来!
  7. C++ 大神 John Carmack 的编程传说
  8. 毕啸南专栏 | 对话澜亭资本创始人刘炯:2018 AI创投领域如何“去伪存真”
  9. 查看IIS进程所对应的应用程序池名称
  10. 现有Android项目引入ReactNative--九步大法
  11. 15-07-22 数据库--存储过程、触发器
  12. Linux镜像源 国内镜像列表
  13. 字节跳动前端外包面试题
  14. STM8单片机STVD环境新建工程笔记
  15. DVWA安装教程(Linux)
  16. matlab将数据集分成训练集和测试集,Matlab实现 把数据集X分割成训练集和测试集...
  17. 特殊符号备用——三角形
  18. 京东接口对接流程(以下举例物流接口):
  19. sql语句插入一条记录同时获取刚插入的id
  20. Linux 文件解压缩及权限管理

热门文章

  1. 记录一下Vue中的created函数所踩到的坑(回调函数不立即生效)
  2. c语言模拟计算机指令流程图,家居分布式温度监测报警系统-传感器课程设计报告 带程序及仿真全套资料...
  3. 杀毒软件McAfee导致客户端访问mscrm超慢
  4. python坐标表示_已知经纬度坐标求两点间距离,用python表示
  5. 传感器实训心得体会_传感器心得体会
  6. Android蓝牙开发 — 经典蓝牙BLE蓝牙
  7. SqlServer计算2个时间的间隔时间(工作日时间),不包括法定节假日和周末
  8. Motivated Word (2)
  9. 【无标题】UE4连接vr外部设备
  10. 三元前驱体废水除镍钴锰