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中有两个类型, ...
随机推荐
- kafka-0.8.1.1总结
文件夹 一. 基础篇 1. 开篇说明 2. 概念说明 3. 配置说明 4. znode分类 5. kafka协议分类 6. Kafka线 ...
- sshd登录攻击
先说简单的防范措施: 1.密码足够复杂 密码的长度大于8位.有数字.大小写字母.特殊字符组合. 2.nmap 扫描 为了避免被扫描到, #看到端口是81 ssh root@192.168.1.63 玩 ...
- git log 查看版本演变历史
1.查看git操作历史 $ git log #git 查看git操作历史 $ git log --oneline #git 简洁的查看git变更记录 $ git log -n4 --onelin ...
- 【LeetCode】Generate Parentheses 解题报告
[题目] Given n pairs of parentheses, write a function to generate all combinations of well-formed pare ...
- windows服务 MVC之@Html.Raw()用法 文件流的读写 简单工厂和工厂模式对比
windows服务 public partial class Service1 : ServiceBase{ System.Threading.Timer recordTimer;public S ...
- mybatis 一对一映射
xml <mapper namespace="com.oracle.dao.one2oneDao"> <sql id="personColum" ...
- Centos修改静态IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0代开配置文件 写入 DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为et ...
- bash_action
https://stackoverflow.com/questions/12076326/how-to-install-maven2-on-redhat-linux #!/bin/bash # Tar ...
- 推断View是否显示在界面上
我们都知道ViewController有viewWillAppear和viewDidAppear等关于页面生命周期的方法,用来对视图做一些管理,比方页面出现时怎么样,页面消失时怎么样.. 可是对于Vi ...
- redis09---redis 服务器端命令
redis 服务器端命令 db0,db1,db2是数据库,外层是服务器,服务器下面有20个数据库. :>time ) "" //多少秒 ) "" //多少 ...