pair用法

用法1:

生成一个pair

pair <int,int> temp;

用法二:

赋值

temp=14;
pari <int,int> x;
x=temp;

用法三:

访问

cout<<temp.first<<endl; //输出pair类型的结构体temp的第一个元素
cout<<temp.second<<endl; //输出第二个元素

用法四:

与map结合更好用:

map <pair<int,int>,int> temp;
pair <int,int> a;
a.first=13;
a.second=15;
temp [a] =147;
cout<<temp[a]<<endl;

用法五:

将 pair 与 优先队列结合起来使用优化 Dijkstra 算法。默认以 pair 的first元素来排序

priority_queue <pair <int, int>, vector <pair <int, int> >, greater <pair <int, int> > Q;

转载于:https://www.cnblogs.com/lixiao189/p/9306685.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值