pair运用
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std; typedef int KeyType; //typedef 为现有类型创建别名 ,定义易于记忆的类型名 为一种数据类型定义一个新名字
typedef std::pair<const KeyType,std::string>Pair; //定义pair对象
typedef std::multimap<KeyType,std::string>MapCode; //定义multimap对象
//multimap中的key是可以重复的,而普通map中的key不可以重复
int main()
{
MapCode codes;
codes.insert(Pair(,"San Francisco")); //插入数据
codes.insert(Pair(,"Oakland"));
codes.insert(Pair(,"Brooklyn"));
codes.insert(Pair(,"Staten Island"));
codes.insert(Pair(,"San Rafael"));
codes.insert(Pair(,"Berkeley")); cout<<"number of cities with area code 415: "<<codes.count()<<endl; //415的个数
cout<<"number of cities with area code 718: "<<codes.count()<<endl; //718的个数
cout<<"number of cities with area code 510: "<<codes.count()<<endl; //510的个数
cout<<"Area Code City\n"; MapCode::iterator it; //iterator 迭代器 提供一种方法访问一个容器(container)对象中各个元素,而又不需暴露该对象的内部细节
for(it=codes.begin();it!=codes.end();++it) //begin()开始,end()结尾
cout<<" "<<(*it).first<<" "<<(*it).second<<endl; //(*t).first代表第一个值,(*t).second代表第二个值 pair<MapCode::iterator,MapCode::iterator> range=codes.equal_range(); //equal range 获取相等元素的子范围
cout<<"cities with area code:\n";
for(it=range.first;it!=range.second;++it) //pair::first是指向子范围左边界的迭代器 pair::last是指向子范围右边界的迭代器
cout<<(*it).second<<endl;
system("pause");
return ;
}

pair运用的更多相关文章
- c++ pair 使用
1. 包含头文件: #include <utility> 2. pair 的操作: pair<T1,T2> p; pair<T1,T2> p(v1,v2); pai ...
- 论Pair的重要性
这些天我在用React和D3做图表,从已经实现的图表里复制了一些坐标轴的代码,发现坐标轴上的n个点里,只有第一个点下面能渲染出文字提示,其余点下面都无法渲染出文字. 和组里的FL一起百思不得其解好几天 ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1010 Weak Pair dfs序+分块
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submissio ...
- pair的使用
#include<iostream> #include<cmath> #include<cstdio> #include<algorithm> #inc ...
- 【C++】pair
STL的pair,有两个值,可以是不同的类型. template <class T1, class T2> struct pair; 注意,pair在头文件utility中,不要inclu ...
- hackerrank Similar Pair
传送门 Problem Statement You are given a tree where each node is labeled from 1 to n. How many similar ...
- uva12546. LCM Pair Sum
uva12546. LCM Pair Sum One of your friends desperately needs your help. He is working with a secret ...
- C++标准库 -- pair
头文件:<utility> 可访问属性: first 第一个值 second 第二个值 可访问方法: swap(pair) 和另外一个pair交换值 其他相关方法: make_pair(v ...
- 2016 大连网赛---Weak Pair(dfs+树状数组)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted ...
- C++学习之Pair
C++学习之Pair Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型, ...
随机推荐
- sql查询语句整理
首先这是我以下语句查询的一个表结构 t_user插入例如以下数据 t_depart中插入例如以下数据 t_role插入例如以下数据 好,建好表后,我们開始数据库查询语句 简单的查询语句 1. 查看表结 ...
- 函数柯里化 curry
一.函数柯里化的特性: (1)参数复用 $.ajax // 示例一 function ajax(type,url,data) { var xhr = new XMLHttpRequest(); xhr ...
- 日常方便使用的Python脚本实现
目录 文件批量重命名 bin文件合并 正文 1.python根据不同条件批量实现文件重命名 因为下载的电视剧名字比较乱,但却按照下载时间顺序依次排列,而手动重命名或者找软件太麻烦,我就自己实现了个: ...
- 一个TAB的jquery简单写法
<style> .honver{ color:red;} </style><script src="../js/jquery-1.9.0.min.js" ...
- poj 3105 Expectation 按位统计
题意: 给n,求sum(i^j)/(n^2),0<=i,j<n.n<10^9 分析: 暴力n^2算法肯定超时.这是logn按位统计算法:按位先算出0出现的个数x,则1出现的个数为n- ...
- CPU die
http://en.wikipedia.org/wiki/CPU_Die Die (integrated circuit) From Wikipedia, the free encyclopedia ...
- hive:Access denied for user 'root'@'%'
配置hive全分布模式时候,在mysql里面创建用户:create user 'hive' identified by 'hive'; 然后给hive帐号分配全部权限: grant all privi ...
- springmvc学习笔记(18)-json数据交互
springmvc学习笔记(18)-json数据交互 标签: springmvc springmvc学习笔记18-json数据交互 springmvc进行json交互 环境准备 加入json转换的依赖 ...
- Posix消息队列相关函数
Posix消息队列(message queue) IPC函数中常用的参数取值: 打开或创建POSIX IPC对象所用的各种oflag常值o_RDONLY 只读O_WRONLY 只写O_RDWD ...
- linux i2c 标准接口(二)
驱动程序操作法:i2c设备的驱动也可以通过普通的设备驱动实现,像往常的驱动一样实现,然后在应用层就可以像读取普通文件一样操作,无需再考虑读写时序.其实普通的设备驱动也可以用两种方法实现, 1)构建字符 ...