set和map的简单用法
、set(集合)map(映射)都属于关联类容器
都支持查询一个元素是否存在并能够有效地获取元素。
set集合的元素总是从小到大排列,set集合通过二分查找树实现。它具备以下两个特点:
①:独一无二的元素:不存在两个值相等的元素
②:元素值就是关键字本身
.#include<set>
using namespace std;
set<int>::iterator it;
int a[]={,,,,};
set<int>s2(a,a+);
for(it=s2.begin();it!=s2.end();it++){
cout<<" "<<*it;
}
.lower_bound():返回第一个不小于元素x的迭代器;
upper——bound():返回第一个大于x的迭代器;
以上两个函数都可以使用二分法实现。
具体实现代码可以看这里:http://www.cnblogs.com/TWS-YIFEI/p/5990976.html.map也是一种关联容器,也是用来存取数据的,数据的组成包括两部分:数据值和关键字;关键字用来唯一的标识数据元素。
. map<char,int>:iterator it;
map<char,int> first;
first['a']=;
for(it=first.begin();it!=first.end();it++){
cout<<(*it).first<<" "<<(*it).second;
//first,second分别是关键字和数据值。
}
set和map的简单用法的更多相关文章
- HDU1004 Let the Balloon Rise(map的简单用法)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- GO的MAP字典简单用法示例
package main import "fmt" type PersonInfo struct { ID string Name string Address string } ...
- leetcode 249 250 set和map的简单用法
leetcode249,利用了STL中的set class Solution { public: vector<int> intersection(vector<int>&am ...
- listActivity和ExpandableListActivity的简单用法
http://www.cnblogs.com/limingblogs/archive/2011/10/09/2204866.html 今天自己简单的总结了listActivity和Expandable ...
- Android MultiType第三方库的基本使用和案例+DiffUtil的简单用法
1.MultiType简单介绍 1.1.MultiType用于比较复杂的页面. 如下图,今日头条用到了MultiType处理各种复杂的页面. 这种还是比较简单的类型.因为一个页面也就这种类型. ...
- python lambda表达式简单用法【转】
python lambda表达式简单用法 1.lambda是什么? 看个例子: g = lambda x:x+1 看一下执行的结果: g(1) >>>2 g(2) >>& ...
- CATransition(os开发之画面切换) 的简单用法
CATransition 的简单用法 //引进CATransition 时要添加包“QuartzCore.framework”,然后引进“#import <QuartzCore/QuartzCo ...
- jquery.validate.js 表单验证简单用法
引入jquery.validate.js插件以及Jquery,在最后加上这个插件的方法名来引用.$('form').validate(); <!DOCTYPE html PUBLIC " ...
- NSCharacterSet 简单用法
NSCharacterSet 简单用法 NSCharacterSet其实是许多字符或者数字或者符号的组合,在网络处理的时候会用到 NSMutableCharacterSet *base = [NSMu ...
随机推荐
- Spring中配置数据源的4种形式
不管采用何种持久化技术,都需要定义数据源.Spring中提供了4种不同形式的数据源配置方式: spring自带的数据源(DriverManagerDataSource),DBCP数据源,C3P0数据源 ...
- Your app declares support for audio in the UIBackgroundModes key in your Info.plist 错误
提交AppStore时候被拒绝 拒绝原因:Your app declares support for audio in the UIBackgroundModes key in your Info.p ...
- 使用App.config管理数据库连接
程序的数据库连接字符串可以保持在程序的配置文件App.config中,便于管理. 将配置文件添加至解决方案: 添加连接信息: <?xml version="1.0"?> ...
- 记一周cdqz训练
#include <cstdio> using namespace std; int main(){ puts("转载请注明出处:http://www.cnblogs.com/w ...
- [信安Presentation]一种基于GPU并行计算的MD5密码解密方法
-------------------paper--------------------- 一种基于GPU并行计算的MD5密码解密方法 0.abstract1.md5算法概述2.md5安全性分析3.基 ...
- POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
- idea maven scala
http://docs.scala-lang.org/tutorials/scala-with-maven.html https://github.com/davidB/scala-archetype ...
- chose.jquery 多选
<select id="language" data-placeholder="选择类别..." class="chosen-select&qu ...
- c# .net获取文件夹下的所有文件(多层递归),并获取区间数据(Jsion,xml等数据)写出到处理文件,学习分享~
static void Main(string[] args) { string path = string.Format(@"C:\Users\Administrator\D ...
- 安装PHP sphinx扩展 sphinx-1.1.0/sphinx.c:105:2: error: too few arguments 错误
表现: /home/sphinx-1.1.0/sphinx.c: In function 'php_sphinx_client_read_property':/home/sphinx-1.1.0/sp ...