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中有两个类型, ...
随机推荐
- Linux C多线程编程-线程互斥
Linux下的多线程编程需要注意的是程序需要包含头文件pthread.h,在生成可执行文件的时候需要链接库libpthread.a或者libpthread.so. 线程创建函数: pthread_cr ...
- winform客户端程序实时读写app.config文件
新接到需求,wcf客户端程序运行时,能实时修改程序的打印机名称: 使用XmlHelper读写 winform.exe.config文件修改后始终,不能实时读取出来,查询博客园,原来已有大神解释了: 获 ...
- UltraEdit UE如何取消保存文件自动备份
高级-配置-文件处理-备份,设置为不备份
- springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定
springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定 标签: springmvc springmvc学习笔记12-springmvc注解开发之包装类型參数绑定 需求 实现方 ...
- html5 式程序员表白
html5 式程序员表白 王海庆 于 星期三, 04/06/2014 - 00:44 提交 今天是个好日子,2014年5月20日,表白的最佳时机,虽说孩子已经四岁.结婚已经五年.可是也不能够偷懒.于是 ...
- Deep Learning for Robotics 资源汇总
1 前言 在最新Nature的Machine Intelligence 中Lecun.Hinton和Bengio三位大牛的Review文章Deep Learning中.最后谈The Future Of ...
- Object类及其常用方法简介
https://www.cnblogs.com/wxywxy/p/6740277.html Object类是一个特殊的类,是所有类的父类,如果一个类没有用extends明确指出继承于某个类,那么它默认 ...
- Arcgis Engine(ae)接口详解(5):IGeometry几何基础操作
//点操作~~~~~~~~~~~~~~~~~~~~~~~~~ //通过坐标生成点 IPoint point = new PointClass(); point.PutCoords(, ); //获取点 ...
- Python开发【2.3 模块】
1.模块导入 import 模块名 from 模块名 import 函数/类/变量 2.模块路径 import sys sys.path 3.模块重新导入 Python3若想在同一次会话中再次运行文件 ...
- vue 单页面(SPA) history模式调用微信jssdk 跳转后偶尔 "invalid signature"错误解决方案
项目背景 vue-cli生成的单页面项目,router使用history模式.产品会在公众号内使用,需要添加微信JSSDK,做分享相关配置. 遇到的问题 相关配置与JS接口安全域名都已经ok,发布后, ...