1 //1.sort函数排序
2 /*
3 #include <iostream>
4 #include <algorithm>
5 using namespace std;
6 int main()
7 {
8 int a[] = { 2,0,3,1,8,2,4,0 };
9 sort(a, a + 3);//对前三个数排序
10 for (int i=0;i<8;++i)
11 {
12 cout << a[i] << " ";
13 }
14 return 0;
15 }*/
16 //2.字符串处理
17 /*
18 #include <iostream>
19 #include <string>
20 using namespace std;
21 int main()
22 {
23 string s = "hello world!";
24 cout<<s<<endl;
25 string a;
26 getline(cin, a);//获取一行数据
27 cout << a << endl;
28 return 0;
29 }*/
30 /*
31 #include <iostream>
32 #include <string>
33 #include <algorithm>
34 using namespace std;
35 int main()
36 {
37 string s;
38 s += "小明";
39 s =s+"小红";
40 int a = 5;
41 s += (a + '0');//把a加入到字符串中
42 cout << s << endl;
43 string x = "741852";
44 sort(x.begin(),x.end());//排序
45 cout << x << endl;
46 string n = "7a4185b2";
47 n.erase(n.begin());//删除第一个元素
48 n.erase(--n.end());//删除最后一个元素
49 cout << n << endl;
50 string m = "147258369";
51 m = m.substr(2, 5);//取72583,从2位置开始往后面截断5个
52 cout << m<<endl;
53 m = m.substr(2, -1);//索引为2,截断到最后
54 cout << m << endl;
55 return 0;
56 }*/
57 //循环
58 /*
59 #include <iostream>
60 using namespace std;
61 int main()
62 {
63 string s="147258369";
64 for (int i=0;i<s.length();++i)
65 {
66 cout <<s[i] ;
67 }
68 cout << endl;
69 //迭代器
70 for (string ::iterator it=s.begin();it!=s.end();++it)
71 {
72 cout << *it;
73 }
74 cout << endl;
75 //迭代器化简
76 for (auto it=s.begin();it!=s.end();++it)
77 {
78 cout << *it;
79 }
80 cout << endl;
81 //C++11新特性
82 for (auto x:s)
83 {
84 cout << x;
85 }
86 return 0;
87 }*/
88 //3.vector.vector相当于数组,模板类型相当于存放的内容
89 /*
90 #include <iostream>
91 #include <vector>
92 using namespace std;
93 int main()
94 {
95 //1.vector构造
96 vector <int> v0;//定义一个空的vector
97 vector<int> v2(4);//定义一个4个大小的vector,初始为0
98 for (auto x:v2)
99 {
100 cout << x;
101 }
102 cout << endl;
103 vector<int> v3(4, 6);//定义一个4个大小的vector,初始值为6
104 for (int i=0;i<v3.size();++i)
105 {
106 cout << v3[i];
107 }
108 cout << endl;
109 vector<int> v{ 8,2,3,4,5 };//定义一个vector,数字为1,2,3,4,5
110 for (auto it=v.begin();it!=v.end();++it)
111 {
112 cout << *it;
113 }
114 cout << endl;
115 cout << v[1];//取索引为1的元素
116 cout << endl;
117 cout << v.at(2);//取索引为1的元素
118 return 0;
119 }*/
120 /*
121 #include <iostream>
122 #include <vector>
123 using namespace std;
124 int main()
125 {
126 //push_back追加内容
127 vector <int> v;
128 v.push_back(1);
129 v.push_back(2);
130 v.push_back(3);
131 v.push_back(4);
132 v.push_back(6);
133 for (int i=0;i<v.size();++i)
134 {
135 cout << v[i];
136 }
137 cout << endl;
138 v.resize(10);//进行重置大小,不赋值默认为0
139 for (int i = 0; i < v.size(); ++i)
140 {
141 cout << v[i];
142 }
143 cout << endl;
144 v.erase(v.begin());
145 v.erase(--v.end());
146 for (int i = 0; i < v.size(); ++i)
147 {
148 cout << v[i];
149 }
150 return 0;
151 }*/
152 /*
153 #include <iostream>
154 #include <vector>
155 #include <algorithm>
156 using namespace std;
157 int main()
158 {
159 //push_back追加内容
160 vector <int> v;
161 v.push_back(1);
162 v.push_back(2);
163 v.push_back(3);
164 v.push_back(4);
165 v.push_back(6);
166 cout << v.front()<<" ";//获取第一个元素
167 cout << v[0]<<" ";
168 cout << *v.begin()<<" ";
169 cout << v.back()<<" ";//获取最后一个元素
170 cout << v[v.size()-1]<<" ";
171 cout << *--v.end()<<endl;
172 //排序
173 //vector<int> v{ 1, 4, 7, 2, 5, 8, 3, 6, 9 };
174 sort(v.begin(), v.end(), less<int>());//从小到大排列
175 for (auto x : v)
176 {
177 cout << x;
178 }
179 cout << endl;
180 sort(v.begin(), v.end(), greater<int>());//从大到小排列
181 for (int i=0;i<v.size();++i)
182 {
183 cout << v[i];
184 }
185 return 0;
186 }*/
187 //4.栈
188 /*
189 #include <iostream>
190 #include <stack>
191 using namespace std;
192 int main()
193 {
194 stack<int> s;
195 //s.push(1);
196 s.push(2);
197 s.push(3);
198 s.push(4);
199 s.push(5);
200 cout << s.top() << endl;
201 s.pop();
202 cout << s.top() << endl;
203 cout << s.size() << endl;
204 bool a = s.empty();
205 cout << a << endl;
206 return 0;
207 }*/
208 //进制转换(十转二)
209 /*
210 #include <iostream>
211 #include <stack>
212 using namespace std;
213 int itob(int decimal)
214 {
215 stack<int> s;
216 int res = 0;
217 while (decimal!=0)
218 {
219 s.push(decimal % 2);
220 decimal /= 2;
221 }
222 while (!s.empty())
223 {
224 res = res * 10 + s.top();
225 s.pop();
226 }
227 return res;
228 }
229 int main()
230 {
231 int n;
232 cin >> n;
233 cout << itob(n);
234 return 0;
235 }*/
236 //输入一行字符串,将字符串逆序打印
237 //输入:hello world
238 //输出:world hello
239 /*
240 #include <iostream>
241 #include <stack>
242 #include <sstream>
243 using namespace std;
244 int main()
245 {
246 string str;
247 stack<string> s;
248 getline(cin, str);
249 stringstream ss;
250 ss << str;
251 while (ss>>str)
252 {
253 s.push(str);
254 }
255 while (!s.empty())
256 {
257 cout << s.top();
258 s.pop();
259 if (s.size() != 0) cout << " ";
260 }
261 return 0;
262 }*/
263 /*#include <iostream>
264 #include <stack>
265 #include <sstream>
266 using namespace std;
267 int main()
268 {
269 //1.字符串转数字
270 string s = "123456";
271 int i;
272 stringstream ss;
273 ss << s; // 将string类型的值放入输入流中
274 ss >> i;// 从sstream中抽取前面插入的string类型的值,赋给int类型
275 cout << i << endl;
276 //方法2
277 string a = "123455";
278 int b = stoi(a);
279 cout << b << endl;
280 //数字转字符串
281 int c = 1234;
282 string out;
283 stringstream aa;
284 aa << c;
285 aa >> out;
286 cout << out << endl;
287 //方法2
288 int d=23123456;
289 cout << to_string(d) << endl;
290 return 0;
291 }*/
292 //4.队列
293 /*
294 #include<iostream>
295 #include<queue>
296 using namespace std;
297 int main()
298 {
299 queue<int> q;
300 q.push(5);
301 q.push(6);
302 q.push(7);
303 cout << q.front() << endl;
304 cout << q.size() << endl;
305 return 0;
306 }*/
307 /*
308 #include<iostream>
309 #include <map>//树状表
310 using namespace std;
311 int main()
312 {
313 map<int, int> m;//有序的,树状结构
314 m[6] = 3;
315 m[5] = 8;
316 m[4] = 9;
317 for (auto it=m.begin();it!=m.end();it++)
318 {
319 cout << it->first << " " << it->second << endl;
320 }
321 for (auto tmp : m)
322 {
323 cout << tmp.first << " " << tmp.second << endl;
324 }
325 return 0;
326 }*/
327 /*
328 #include<iostream>
329 #include <unordered_map>//哈希表
330 using namespace std;
331 int main()
332 {
333 unordered_map<int, int> m;//无序的
334 m[6] = 3;
335 m[5] = 8;
336 m[4] = 9;
337 m[2] = 6;
338 m[1] = 0;
339 for (auto it = m.begin(); it != m.end(); it++)
340 cout << it->first << " " << it->second << endl;
341 for (auto tmp : m) {
342 cout << tmp.first << " " << tmp.second << endl;
343 }
344 return 0;
345 }*/
346 //pair的用法,将map转成vector进行排序
347 /*
348 #include<iostream>
349 #include <unordered_map>//哈希表
350 #include <algorithm>
351 using namespace std;
352 bool cmp(pair<int, int> a, pair<int, int> b)
353 {
354 return a.first > b.first;
355 }
356 int main()
357 {
358 unordered_map<int, int> m;//无序的
359 m[4] = 9;
360 m[2] = 6;
361 m[6] = 3;
362 m[5] = 8;
363 m[1] = 0;
364 vector<pair<int, int>> v(m.begin(), m.end());
365 sort(v.begin(), v.end(), cmp);
366 for (auto tmp : v) {
367 cout << tmp.first << tmp.second << endl;
368 }
369 return 0;
370 }*/
371 //集合,计数去重
372 /*
373 #include<iostream>
374 #include <set>
375 #include <unordered_set>
376 using namespace std;
377 int main()
378 {
379 set<int> s;//树状结构,有序
380 unordered_set<int> s2;//哈希结构,无序,快
381 s.insert(3);
382 s.insert(4);
383 s.insert(4);
384 s.insert(4);
385 s.insert(5);
386 cout << s.size() << endl;
387 for (auto tmp:s)
388 {
389 cout << tmp << " ";
390 }
391 cout << endl;
392 for (auto it=s.begin();it!=s.end();++it)
393 {
394 cout << *it << " ";
395 }
396 cout << endl;
397 return 0;
398 }*/
399 //deque双端队列
400 /*
401 #include<iostream>
402 #include <deque>
403 #include <algorithm>
404 using namespace std;
405 int main()
406 {
407 deque<int> d;
408 //4 9 1 2
409 d.push_back(1);
410 d.push_back(6);
411 d.push_back(5);
412 d.push_back(7);
413 d.push_back(2);
414 d.push_front(9);
415 d.push_front(5);
416 d.push_front(3);
417 d.push_front(6);
418 d.push_front(4);
419 d.pop_back();
420 d.pop_front();
421 for (auto tmp:d)
422 {
423 cout << tmp <<" ";
424 }
425 cout << endl;
426 sort(d.begin(), d.end(), greater<int>());
427 for (auto it=d.begin();it!=d.end();++it)
428 {
429 cout << *it <<" ";
430 }
431 cout << endl;
432 return 0;
433 }*/
434 //list双向链表
435 #include<iostream>
436 #include <list>
437 using namespace std;
438 int main()
439 {
440 list<int> li;
441 li.push_back(6);
442 li.push_front(5);
443 li.emplace_front(9);//在开头添加元素
444 li.emplace_back(10);
445 li.insert(++li.begin(), 2);
446 for (auto tmp:li)
447 {
448 cout << tmp << " ";
449 }
450 cout << endl;
451 for (auto it = li.begin(); it != li.end(); it++) cout << *it << endl;
452 return 0;
453 }

C++stl简单使用的更多相关文章

  1. C++ STL 简单记录

    1,STL提供三种类型的组件:容器.迭代器.算法. 容器: 顺序容器(vector.list.deque.string等)是一系列元素的有序集合: 关联容器(set.multiset.map.mult ...

  2. STL简单的介绍

    我们要知道C++的含义:C语言 + 类 + 模板  (STL就是典型的代表) STL是Standard Template Library的简称,中文名是标准模库.从根本上说,STL是一些“容器”的集合 ...

  3. <<C++标准程序库>>中的STL简单学习笔记

    0. 内容为个人学习笔记, 仅供参考, 如有错漏, 欢迎指正! 1. STL中的所有组件都是由模板构成的, 所以其元素可以是任意型别的. 组件有: - 容器: 管理某类对象的集合. 不同的容器有各自的 ...

  4. STL简单应用问题

    问题: Input输入的第一行是一个整数T( 1 <= T <= 100 ),表示有几组输入数据.每组输入由4部分组成:(1)一个字典,最多包含2000个单词,每个单词一行.(2)一行字符 ...

  5. 复合词UVa10391(STL简单应用)

    一.题目 输入一系列由小写字母组成的单词.输入已按照字典序排序(这句话就是个陷阱),且不超过120000个.找出所有的复合词,即恰好由两个单词连接而成的单词. 二.解题思路 要么枚举两两拼接的情况,O ...

  6. set STL 简单说说

    set 这个容器,可以排序,以及去掉重复的东西 #include<bits/stdc++.h> using namespace std; int main() { string s; se ...

  7. 标准模板库--STL

    标准模板库STL 1.泛型程序设计 C++ 语言的核心优势之一就是便于软件的重用 C++中有两个方面体现重用: 1.面向对象的思想:继承和多态,标准类库 2.泛型程序设计(generic progra ...

  8. STL(常用)

    STL 简单记录.讲解一些初级阶段常用的用法. STL是C++的一个标准模板库,其中包含了许多在计算机领域常用的基本数据结构以及基本算法.STL主要依赖于模板,使得STL具有广泛的通用性.这篇文章旨在 ...

  9. DFS系列 POJ(自认为的讲解)

    C - Sum It Up POJ1564 题意: 给你一个N,然后给你一堆数The numbers in each list appear in nonincreasing order, and t ...

随机推荐

  1. Android Choreographer 源码分析

    Choreographer 的作用主要是配合 Vsync ,给上层 App 的渲染提供一个稳定的 Message 处理的时机,也就是 Vsync 到来的时候 ,系统通过对 Vsync 信号周期的调整, ...

  2. [Luogu P3959] 宝藏 (状压DP+枚举子集)

    题面 传送门:https://www.luogu.org/problemnew/show/P3959 Solution 这道题的是一道很巧妙的状压DP题. 首先,看到数据范围,应该状压DP没错了. 根 ...

  3. NOIP 2017 Day1 解题报告

    总分:100分 T1,小凯的疑惑, 100分 T2,时间复杂度,0分 T3,逛公园,0分 T1 ###题意简化: 给定两个互质的数字,输出最大不能表示的数: 基础数论题目 代码: #include&l ...

  4. Python爬虫实战详解:爬取图片之家

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理 如何使用python去实现一个爬虫? 模拟浏览器请求并获取网站数据在原始数据 ...

  5. 什么是 RedLock

    Redis 官方站这篇文章提出了一种权威的基于 Redis 实现分布式锁的方式名叫 Redlock,此种方式比原先的单节点的方法更安全.它可以保证以下特性: 安全特性:互斥访问,即永远只有一个 cli ...

  6. 《Web接口开发与自动化测试》学习笔记(三)

    一.认证系统 使用django本身自带的认证系统 1.登录admin后台 1. 先建立一个管理员用户: > python manage.py creatsuperuser 输入用户名.邮箱和密码 ...

  7. 针对DEV XtraReport中没有radiobuttonlist的替代方法

     private void PrintingSystem_EditingFieldChanged(object sender, DevExpress.XtraPrinting.EditingField ...

  8. VMware虚拟机 - 解决 Vmware 启动虚拟机报:该虚拟机似乎正在使用中。 如果该虚拟机未在使用,请按“获取所有权(T)”按钮获取它的所有权。否则,请按“取消(C)”按钮以防损坏的问题

    问题背景 当虚拟机仍然在运行时,直接关闭电脑,下次重开电脑并想重新启动虚拟机时报了下图问题 解决方案 进入虚拟机所在目录,把 .lck 后缀的文件都删完 Vmware 重新启动虚拟机 成功!!

  9. full nat

    在餐馆吃饭时,连接无线网络后访问某网页会自动弹出一个认证页面,我想大家都经历过..... 其网络拓扑如下: sta-------------网络设备--------------公网 比如sta 终端i ...

  10. fork-vfork -exit&_exit

    昨天帮人查bug,发现了一个vfork fork exit  _exit不分导致的问题. 使用vfork 后调用exit导致的问题. 主要需要弄清楚他们之间的区别: 1.  fork  ():子进程拷 ...