![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
STL
si_yu_ge
任逍遥
展开
-
C++ priority_queue 基本操作
#include<queue>using namespace std;int main(){ priority_queue <int> a; priority_queue <double> b; priority_queue < int, vector <int>, greater <int> > c; priority_queue <int> d( a);} #include<queue>原创 2020-09-28 08:16:11 · 95 阅读 · 0 评论 -
C++ queue 基本操作
#include<queue>#include<list>using namespace std;int main(){ queue <int> a; queue <double> b; queue <double, list <double> > c;//use list queue <int> d( a);} #include<queue>#include<iostream>原创 2020-09-28 08:15:23 · 195 阅读 · 0 评论 -
C++ stack 基本操作
#include<stack>#include<vector>using namespace std;int main(){ stack <int> a; stack <double> b; stack <int, vector <int> > c; // 选用vector stack <int> d( a);}#include<stack>#include<iostream>原创 2020-09-28 08:13:41 · 254 阅读 · 0 评论 -
C++ lower_bound upper_bound
#include<vector>#include<iostream>#include<algorithm>using namespace std;void show( const vector <string> a){ for(auto p = a.begin(); p != a.end(); p ++) cout << *p << endl; cout << endl;}int main(){ ve原创 2020-09-26 12:19:21 · 132 阅读 · 0 评论 -
C++ partition stable_partition
#include<vector>#include<algorithm>#include<iostream>using namespace std;void show( const vector <int> a){ for(auto p = a.begin(); p != a.end(); p ++) cout << *p << ' '; cout << endl;}int main(){ vecto原创 2020-09-26 12:18:17 · 105 阅读 · 0 评论 -
C++ binary_search unique
#include<vector>#include<string>#include<iostream>#include<algorithm>using namespace std;void show( const vector <string> a){ for(auto p = a.begin(); p != a.end(); p ++) cout << *p << endl; cout <<原创 2020-09-26 12:17:19 · 115 阅读 · 0 评论 -
C++ replace replace_if
#include<vector>#include<iostream>#include<algorithm>using namespace std;void show( vector <int> &a){ for(auto p = a.begin(); p != a.end(); p ++) cout << *p << ' '; cout << endl;}int main(){ vector原创 2020-09-26 12:16:12 · 138 阅读 · 0 评论 -
C++ copy_backward
#include<vector>#include<iostream>#include<algorithm>using namespace std;int main(){ vector <int> a{ 1, 2, 3, 4, 5}, b(5); //copy_backward( iterator first, iterator last, iterator) 沿反方向复制 返回一个指向复制结束位置的的迭代器 auto i = copy_b原创 2020-09-26 09:54:13 · 159 阅读 · 0 评论 -
C++ copy copy_if remove remove_if
#include<vector>#include<list>#include<iostream>#include<algorithm>using namespace std;void show( const vector<int> &a){ for(auto p = a.begin(); p != a.end(); p ++) cout << *p << ' '; cout << en原创 2020-09-26 09:53:34 · 97 阅读 · 0 评论 -
C++ transform
#include<string>#include<vector>#include<deque>#include<algorithm>#include<iostream>#include<functional>using namespace std;template <typename T>void show(const T& a){ for(auto p = a.begin(); p != a.e原创 2020-09-26 09:52:15 · 121 阅读 · 0 评论 -
C++ for_each
#include<vector>#include<string>#include<iostream>#include<algorithm>using namespace std;struct show{ int count; show (): count(0){} void operator()(const char& c){ cout << c; count ++; }};int main(){ vec原创 2020-09-26 09:51:11 · 70 阅读 · 0 评论 -
C++ generate generate_n
#include<vector>#include<list>#include<iostream>#include<algorithm>using namespace std;template <typename T>void show( const T& a){ for(auto p = a.begin(); p != a.end(); p ++) cout << *p << ' '; cout原创 2020-09-26 09:50:07 · 326 阅读 · 0 评论 -
C++ fill fill_n
#include<algorithm>#include<vector>#include<iostream>using namespace std;int main(){ vector <int> a(10); //fill( iterator first, iterator last, key) fill( a.begin(), a.end(), 1); a.resize(15); //fill_n( iterator first, n原创 2020-09-25 17:22:34 · 82 阅读 · 0 评论 -
C++ search search_n
#include<vector>#include<iostream>#include<list>#include<algorithm>using namespace std;int main(){ vector <int> a; for(int i = 0; i < 10; i ++) a.push_back( i); a.push_back( 9); a.push_back( 9); for(auto i =原创 2020-09-25 17:21:58 · 306 阅读 · 0 评论 -
C++ count count_if
#include<vector>#include<iostream>#include<algorithm>using namespace std;int main(){ vector <int> a; a.push_back( 1); a.push_back( 1); a.push_back( 2); a.push_back( 2); a.push_back( 3); a.push_back( 3); int count1, co原创 2020-09-25 17:21:20 · 104 阅读 · 0 评论 -
C++ find find_if
#include<vector>#include<algorithm>#include<iostream>using namespace std;int main(){ vector <int> a{ 1, 2, 3, 4, 5}; int x; cout << "put in the value you want to search" << endl << '>'; cin >> x原创 2020-09-25 17:20:42 · 238 阅读 · 0 评论 -
C++ lambda表达式的通用格式
#include<bits/stdc++.h>using namespace std;int main(){ //在此总结一下lambda表达式的通用格式 //[ State(&引用__无&时 状态变量为只读模式,不可在表达式内修改) 1, State(&) 2, ...] //( elemtype(&引用) 1, elemtype(&) 2, ...] //(mutable)__用于在表达式内修改状态变量且修改只在表达式内有效 __当状态变原创 2020-09-25 12:22:18 · 353 阅读 · 0 评论 -
C++ 二元谓词对应的lambda表达式
#include<vector>#include<string>#include<algorithm>#include<iostream>using namespace std;template <typename T>void show( const T& a){ for(auto p = a.begin(); p != a.end(); p ++) cout << *p << endl;原创 2020-09-25 12:21:21 · 250 阅读 · 0 评论 -
C++ 二元函数对应的lambda表达式
#include<algorithm>#include<vector>#include<iostream>using namespace std;int main(){ vector <int> a{ 1, 2, 3, 4, 5}, b( a), c( a.size()); //二元函数对应的lambda表达式 transform( a.begin(), a.end(), b.begin(), c.begin(),[](int a, int原创 2020-09-25 12:20:28 · 355 阅读 · 0 评论 -
C++ 接受状态变量的lambda表达式
#include<algorithm>#include<vector>#include<iostream>using namespace std;int main(){ vector <int> a{ 1, 3, 5, 7, 9, 11}; int x; cout << "input 除数 x" << endl << '>'; cin >> x; //通过捕获列表[...]接受状原创 2020-09-25 12:19:50 · 335 阅读 · 0 评论 -
C++ 一元谓词对应的lambda表达式
#include<vector>#include<algorithm>#include<iostream>using namespace std;int main(){ vector <int> a{ 1, 3, 5, 7, 9, 11}; //一元谓词对应的lambda表达式 -- a > 7 是 return ture auto p = find_if( a.begin(), a.end(), [](int& a){原创 2020-09-25 12:17:11 · 314 阅读 · 0 评论 -
C++ 一元函数对应的 lambda表达式
#include<algorithm>#include<vector>#include<list>#include<iostream>using namespace std;int main(){ vector <int> a{ 1, 2, 3, 4, 5}; // 一元函数对应的 lambda表达式 for_each( a.begin(), a.end(), [](int& a){ cout <<原创 2020-09-25 12:16:08 · 204 阅读 · 0 评论 -
C++ 一元函数 一元谓词 二元函数 二元谓词
21C++ 的 21章#include<algorithm>#include<vector>#include<list>#include<iostream>using namespace std;template <typename T>struct show{ void operator() (const T& a) const{ cout << a << ' '; }};int mai原创 2020-09-24 20:55:45 · 392 阅读 · 0 评论 -
STL map multimap 一些基本操作
21C++ STL map 一些基本操作#include<map>#include<string>using namespace std;int main(){ map <int, string> a1; multimap <int, string> a2; map <int, string> b1( a1); multimap <int, string> b2( a2); map <int, stri原创 2020-09-23 17:09:27 · 93 阅读 · 0 评论 -
21C++ STL set multiset 一些基本操作
一些基本操作#include<set>using namespace std;int main(){ set <int> a{ 1, 2, 3, 4}; multiset <int> b; set <int> c( a); multiset <int> d( a.begin(), a.end());//两个描述边界的迭代器 }#include<set>#include<iostream>us原创 2020-09-22 19:38:19 · 102 阅读 · 0 评论 -
21C++ STL list 基本操作
一些基本操作#include<list>#include<vector>using namespace std;int main(){ list <int> a;//空链表 list <int> b(10);//10个元素 list <int> c( 10, 90);// 10 个 90 vector <int> d( 5, 9); list <int> e( d.cbegin()原创 2020-09-21 22:25:59 · 73 阅读 · 0 评论 -
21C++ STL forward_list 单向链表
一些基本操作#include<iostream>using namespace std;template <typename T>void show(const T& a){ for(auto i = a.begin(); i != a.end(); i ++) cout << *i << ' '; cout << endl;}int main(){ forward_list <int> a; //单向原创 2020-09-21 22:25:38 · 110 阅读 · 0 评论 -
反片语 UVA 156
输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词。 在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列(所有大写字母在所有小写字母的前面)。Sample Inputladder came tape soon leader acme RIDE lone Dreis peatScAlE orb eye Rides dealer NotE derail LaCeS drIednoel dire Disk mace Rob d原创 2020-09-21 08:42:05 · 174 阅读 · 0 评论 -
21C++ STL vector 练习题
17章作业#include<vector>#include<algorithm>#include<iostream>using namespace std;int fun(){ cout << "please select" << endl; cout << "1 to add data" << endl; cout << "2 to find data" << endl; co原创 2020-09-21 08:16:12 · 942 阅读 · 0 评论 -
21C++ STL deque
一些基本操作#include<deque>#include<iostream>#include<algorithm>using namespace std;int main(){ deque <int> a; //末尾插入 a.push_back(4); a.push_back(5); a.push_back(6); //数组下标法 for(int i = 0; i < a.size(); i ++) cout原创 2020-09-20 21:21:42 · 56 阅读 · 0 评论 -
STL vector
一些基本操作#include<vector>#include<iostream>using namespace std;int main(){ vector <int> a( 10, 90); for(int i = 0; i < a.size(); i ++) cout << a[i] << ' '; cout << endl; vector <int> b (a); for(int i原创 2020-09-20 21:19:34 · 68 阅读 · 0 评论 -
21C++ STL string 习题
1.判断单词是否回文。#include<iostream>#include<string>#include<algorithm>using namespace std;int main(){ string s, s1; cin >> s; s1 = s; reverse( s.begin(), s.end()); if(s==s1) cout << "yes" << endl; else cout <<原创 2020-09-19 16:30:52 · 200 阅读 · 0 评论 -
21C++ 16.2.7 字符串的大小写转换
字符串的大小写转换程序清单16.7#include<string>#include<algorithm>#include<iostream>using namespace std;int main(){ string s("hello"); //transform(数据起始迭代器, 数据结束迭代器, 写入位置的迭代器, 函数) //::toupper transform( s.begin(), s.end(), s.begin(), ::toup原创 2020-09-16 22:48:39 · 58 阅读 · 0 评论 -
21C++ 16.2.6 字符串反转
字符串反转程序清单16.6#include<string>#include<iostream>#include<algorithm>using namespace std;int main(){ string s("hello world!!!"); //reverse 反转 两个迭代器之间的字符 reverse ( s.begin(), s.end()); cout << s << endl; string s1("原创 2020-09-16 22:46:30 · 98 阅读 · 0 评论 -
21C++ 16.2.5 截短STL string
截短STL string程序清单16.5#include<iostream>#include<string>#include<algorithm>using namespace std;int main(){ string s("Hello world"); // 1 from a to b s.erase( 5, 10); cout << s << endl; //2 删除指向 s中某一字符的迭代器 strin原创 2020-09-16 22:44:34 · 89 阅读 · 0 评论 -
21C++ 16.2.3 拼接字符串
程序清单 16.3#include<string>#include<iostream>using namespace std;int main(){ string s1 ("ni"), s2 (" shi"), s3 (" shui"); const char* p = "???"; // use += s1 += s2; //or s1 = s1 + s2; s1 是 ni shi; cout << s1 << endl; //原创 2020-09-16 16:15:18 · 74 阅读 · 0 评论 -
21C++ 16.2.4 在string中查找字符或字符串
在string中查找字符或字符串程序清单16.4#include<string>#include<iostream>using namespace std;int main(){ string s = "You can do it!"; //find substring "it" from position 0 int p1 = s.find("it", 0); //use string::npos check if substring was foun原创 2020-09-16 16:11:36 · 229 阅读 · 0 评论 -
21C++ 16.1 16.2 string 的 初始化和访问
string 的 初始化和访问#include<string>#include<iostream>using namespace std;int main(){ // string 的 初始化 string s = "ni hao"; // or string s (ni hao); string s1 (s); cout << s1 << endl; const char* p = "hello "; string s2 = p;原创 2020-09-16 11:03:07 · 88 阅读 · 0 评论 -
21C++ 15.1
21C++程序清单15.1 在vector中查找元素及其位置#include<algorithm>#include<vector>#include<iostream>using namespace std;int main(){ vector<int>a; a.push_back(1); a.push_back(3); a.push_back(5); a.push_back(7); //用迭代器进行遍历 vector<int原创 2020-09-15 20:22:11 · 100 阅读 · 0 评论 -
刘书5.2.1
大理石在哪儿(UVa 10474)#include<cstdio>#include<algorithm>using namespace std;const int Max = 10000;int main(){ int n, q, a[Max], x; //读入 n q while(scanf("%d%d", &n, &q) && n){ //读入 for(int i = 0; i < n; i++) scan原创 2020-09-15 18:59:11 · 104 阅读 · 0 评论