pair 函数 (STL)
来源:互联网 发布:linux查看端口号命令 编辑:程序博客网 时间:2024/05/04 00:57
》》贪心 (区间问题)
》》使用:
pair <int, int> a[11000];
/*法二
typedef pair<int,int> Pii;
Pii a[11000];
*/
》》 pair 类也是标准库的一部分,它使得我们可以在单个对象内部把相同类型或不同类型的两个值关联起来。为了使用pair 类,我们必须包含下面的头文件
#include <utility>
例如
pair< string, string > author( "James", "Joyce" );
创建了一个pair 对象author ,它包含两个字符串,分别被初始化为 James 和 Joyce 我们可以用成员访问符号 member access notation 访问pair 中的单个元素,它们的名字为first 和second ,例如
string firstBook;
if ( author.first == "James" && author.second == "Joyce" )
firstBook = "Stephen Hero";
如果我们希望定义大量相同pair 类型的对象 那么最方便的做法就是用typedef 如下所示
typedef pair< string, string > Authors;
Authors proust( "marcel", "proust" );
Authors joyce( "james", "joyce" );
Authors musil( "robert", "musil" );
下面是第二个pair, 一个元素持有对象的名字, 另一个元素持有指向其符号表入口的指针
// 前向声明 (forward declaration)
class EntrySlot;
extern EntrySlot* look_up( string );
typedef pair< string, EntrySlot* > SymbolEntry;
SymbolEntry current_entry( "author", look_up( "author" ));
// ...
if ( EntrySlot *it = look_up( "editor" ))
{
current_entry.first = "editor";
current_entry.second = it;
}
》》使用:
pair <int, int> a[11000];
/*法二
typedef pair<int,int> Pii;
Pii a[11000];
*/
》》 pair 类也是标准库的一部分,它使得我们可以在单个对象内部把相同类型或不同类型的两个值关联起来。为了使用pair 类,我们必须包含下面的头文件
#include <utility>
例如
pair< string, string > author( "James", "Joyce" );
创建了一个pair 对象author ,它包含两个字符串,分别被初始化为 James 和 Joyce 我们可以用成员访问符号 member access notation 访问pair 中的单个元素,它们的名字为first 和second ,例如
string firstBook;
if ( author.first == "James" && author.second == "Joyce" )
firstBook = "Stephen Hero";
如果我们希望定义大量相同pair 类型的对象 那么最方便的做法就是用typedef 如下所示
typedef pair< string, string > Authors;
Authors proust( "marcel", "proust" );
Authors joyce( "james", "joyce" );
Authors musil( "robert", "musil" );
下面是第二个pair, 一个元素持有对象的名字, 另一个元素持有指向其符号表入口的指针
// 前向声明 (forward declaration)
class EntrySlot;
extern EntrySlot* look_up( string );
typedef pair< string, EntrySlot* > SymbolEntry;
SymbolEntry current_entry( "author", look_up( "author" ));
// ...
if ( EntrySlot *it = look_up( "editor" ))
{
current_entry.first = "editor";
current_entry.second = it;
}
0 0
- pair 函数 (STL)
- STL Pair
- pair(STL)
- [STL] pair
- STL::pair
- STL-pair
- stl pair
- STL pair
- stl-map stl-pair
- 【STL】STL之pair
- stl map用法和make_pair函数和pair结构体
- 【pair函数】
- C++ STL Pair
- C++ STL Pair
- stl pair 应用
- C++STL学习Pair
- poj2002 STL pair解法
- STL pair demo
- 27.swift基础
- ios视图frame和bounds的对比
- 致10年前自己的一封信,谁与我同行
- 28.swift高级
- centos直接yum安装nginx
- pair 函数 (STL)
- RabbitMQ监控(3)——核心监控类实现
- BIEE系统C组件启动不了 libxerces-c.so.28
- github常见操作和常见错误!错误提示:fatal: remote origin already exists.
- 演练:从头开始创建 MSBuild 项目文件
- Linux解压缩命令
- (整理)Java实现链表--找到两个链表的第一个公共结点(网易笔试题2016)
- 从30岁到35岁:为你的生命多积累一些厚度
- C++:简单文件输入/输出