我是靠谱客的博主 小巧仙人掌,这篇文章主要介绍STL容器模板,现在分享给大家,希望可以做个参考。

map用于保存具有映射关系的数据,Map集合里保存着两组值,一组用于保存Map的key,另一组保存着Map的value。所有的key是不能重复的并且没有顺序。

deque和vector是基于动态数组的。
List是基于链表的。
map是无序的。

C++容器
https://www.cnblogs.com/cxq0017/p/6555533.html
https://blog.csdn.net/shuzfan/article/details/53115922

c++中有两种类型的容器:顺序容器和关联容器,顺序容器主要有:vector、list、deque等。其中vector表示一段连续的内存地址,基于数组的实现,list表示非连续的内存,基于链表实现。deque与vector类似,但是对于首元素提供删除和插入的双向支持。关联容器主要有map和set。map是key-value形式的,set是单值。map和set只能存放唯一的key值,multimap和multiset可以存放多个相同的key值。
迭代器!!!!!!!!!!!!!!!!!!!!!!!!
https://blog.csdn.net/shuzfan/article/details/53115922
啊啊啊啊啊好累,学无止境

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
在这里插入代码片 #include<iostream> #include<string> #include<map> using namespace std; int main(){ string str; map<map<string,int>,int> m_deg;//m_deg次数 map<string,int> m_index;//m_index,文件输入位置 while(cin>>str){ int num; cin>>num; map<string,int> k; k[str]=num; m_deg[k]+=1; if(m_deg[k]>1){ continue; } int len=str.length(),index=str.length()-1; for(;str[index]!='\'&&(len-index)<=16;index--); //cout<<str.substr(index+1,len-index)<<' '<<num<<' '<<i<<endl; m_index[str]=index+1; } map<map<string,int>,int>::iterator it;//迭代器 for(it=m_deg.begin();it!=m_deg.end();it++){ map<string,int> k=it->first; map<string,int>::iterator itk=k.begin(); map<string,int>::iterator it_index; it_index=m_index.find(itk->first);//如果存在该键就返回该map cout<<it_index->first.substr(it_index->second,it_index->first.length()); cout<<' '<<itk->second<<' '<<it->second<<endl; } return 0; }

最后

以上就是小巧仙人掌最近收集整理的关于STL容器模板的全部内容,更多相关STL容器模板内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部