#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运用的更多相关文章

  1. c++ pair 使用

    1. 包含头文件: #include <utility> 2. pair 的操作: pair<T1,T2> p; pair<T1,T2> p(v1,v2); pai ...

  2. 论Pair的重要性

    这些天我在用React和D3做图表,从已经实现的图表里复制了一些坐标轴的代码,发现坐标轴上的n个点里,只有第一个点下面能渲染出文字提示,其余点下面都无法渲染出文字. 和组里的FL一起百思不得其解好几天 ...

  3. 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 ...

  4. pair的使用

    #include<iostream> #include<cmath> #include<cstdio> #include<algorithm> #inc ...

  5. 【C++】pair

    STL的pair,有两个值,可以是不同的类型. template <class T1, class T2> struct pair; 注意,pair在头文件utility中,不要inclu ...

  6. hackerrank Similar Pair

    传送门 Problem Statement You are given a tree where each node is labeled from 1 to n. How many similar ...

  7. uva12546. LCM Pair Sum

    uva12546. LCM Pair Sum One of your friends desperately needs your help. He is working with a secret ...

  8. C++标准库 -- pair

    头文件:<utility> 可访问属性: first 第一个值 second 第二个值 可访问方法: swap(pair) 和另外一个pair交换值 其他相关方法: make_pair(v ...

  9. 2016 大连网赛---Weak Pair(dfs+树状数组)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted ...

  10. C++学习之Pair

    C++学习之Pair Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型, ...

随机推荐

  1. VC++下编译Libgeotiff(含Libtiff)

    转自原文Win10+VC++下编译Libgeotiff(含Libtiff)详细图文教程 GeoTiff是包含地理信息的一种Tiff格式的文件.Libgeotiff就是一个操作GeoTiff文件的库.同 ...

  2. 【spring data jpa】报错如下:Caused by: javax.persistence.EntityNotFoundException: Unable to find com.rollong.chinatower.server.persistence.entity.staff.Department with id 0

    报错如下: org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com.rollong.chi ...

  3. BIM

    BIM进入中国已经有十来个年头,随着对BIM概念的深入了解.当前国内BIM应用逐渐由三维模型的可视化应用升级为基于BIM模型的信息进行项目精细化动态管理. 传统粗放的项目管理方法是工程项目难以进行精细 ...

  4. 使用webstorm+webpack构建简单入门级“HelloWorld”的应用&&构建使用jquery来实现

    使用webstorm+webpack构建简单入门级“HelloWorld”的应用&&构建使用jquery来实现 1.首先你自己把webstorm安装完成. 请参考这篇文章进行安装和破解 ...

  5. Service具体解释(一):什么是Service

    < Service具体解释(一):什么是Service> < Service具体解释(二):Service生命周期> <Service具体解释(三):Service的使用 ...

  6. nginx配置初步

    nginx配置初步 1,切换至nginx目录,找到配置文件目录 cd /etc/nginx/conf.d 2,拷贝一份conf文件 sudo cp default.conf head.conf 3,进 ...

  7. apache多网站配置

    前言  虽说apache安装好后给了我们一个默认的一个网站.并且我们还能够将这个默认的网站改动成我们自己的网站.可是这似乎还不能全然满足我们的须要,由于当我们要在本机上开发(phpWeb)或者測试另外 ...

  8. MySQL Community Server 5.6和MySQL Installer 5.6

    mysql community server是mysql社区版的数据库服务器.即数据库软件. mysql installer是mysql软件的安装管理器,能够通过installer来选择安装mysql ...

  9. Java数据结构与算法之排序

    排序从大体上来讲,做了两件事情: 1.比較两个数据项: 2.交换两个数据项.或复制当中一项 一.冒泡排序 大O表示法:交换次数和比較次数都为O(N*N). 算法原理: 1.比較相邻的元素.假设第一个比 ...

  10. Quick-Cocos2d3.2RC1在Code IDE中实现代码提示

    之前写Lua最痛苦的就是代码提示问题,如今官方给了IDE很好用.以下说Quick使用IDE加入代码提示问题. 第一步:制作api提示压缩包. 须要使用控制台实现方法例如以下: 1.找到framewor ...