11.3.5
来源:互联网 发布:网络电视32寸多少钱 编辑:程序博客网 时间:2024/05/16 10:31
11.27
当我想知道知道,对应关键字的元素有几个的时候,我会使用count
当我只想知道它在不在的时候,我会使用find
11.28
std::map<std::string ,std::vector<int>> hh{ {"p",{0,1,2,3}} }auto iter= hh.find("p");
11.29
lower_bound和upper_bound 会返回一样的迭代器,指向关键字的插入点
equal_range会返回一个pair,两个迭代器和上面一样
11.30
pos是一个pair
pos.first 是一个迭代器指向关键字匹配的元素
pos.first->second 是元素的第二项,是value部分
11.31
@pezy
#include <map>#include <string>#include <iostream>using std::string;int main(){ std::multimap<string, string> authors{ { "alan", "DMA" }, { "pezy", "LeetCode" }, { "alan", "CLRS" }, { "wang", "FTP" }, { "pezy", "CP5" }, { "wang", "CPP-Concurrency" } }; // want to delete an element that author is [Alan], work is [112]. string author = "pezy"; string work = "CP5"; auto found = authors.find(author); auto count = authors.count(author); while (count) { if (found->second == work) { authors.erase(found); break; } ++found; --count; } for (const auto &author : authors) std::cout << author.first << " " << author.second << std::endl;}
11.32
@pezy
#include <map>#include <set>#include <string>#include <iostream>using std::string;int main(){ std::multimap<string, string> authors{ { "alan", "DMA" }, { "pezy", "LeetCode" }, { "alan", "CLRS" }, { "wang", "FTP" }, { "pezy", "CP5" }, { "wang", "CPP-Concurrency" } }; std::map<string, std::multiset<string>> order_authors; for (const auto &author : authors) order_authors[author.first].insert(author.second); for (const auto &author : order_authors) { std::cout << author.first << ": "; for (const auto &work : author.second) std::cout << work << " "; std::cout << std::endl; }}
0 0
- 11.3.5
- 11.3.5节练习
- 11.3
- 11.3
- 11.3
- 11.3
- 11.3
- 11.3
- 第十一章 11.3.5节练习
- 11.3.5 为 C# 实现延迟值
- C++ Primer 第5版--练习11.3
- 11.3.5 一个多播例子的服务器端
- C++Primer第五版 11.3.5节练习
- JavaScript高级程序设计之DOM 扩展之HTML5之自定义数据属性第11.3.5讲
- 11.3.1
- 11.3.2
- 11.3.4
- 11.3.6
- 【贪心算法】背包问题
- 【Leetcode】205. Isomorphic Strings
- 算法
- Python:数据文件的打开模式和操作方法
- 【Java语言程序设计(基础篇)第10版 练习题答案】Practice_9_4
- 11.3.5
- c指针应用:键值对"key=value"字符串,在开发中经常使用
- 算法训练 5-1最小公倍数
- win10,ubuntu双系统和win10,红帽双系统的安装的异同
- OI心得::学会经常使用类,重载运算符和库。
- nginx配置虚拟主机
- Matlab编程与数据类型 -- 开关语句switch/end
- CodeForces 762F. Tree nesting
- 【Android】Android中的RecyclerView的基本使用