You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
/*
知识点内容: C++ STL pair详解
pair是一种模板类型, 其中包含两个数据值, 两个数据的类型可以不同。如果一个函数有两个返回值的话, 如果是相同类型, 就可以用数组返回, 如果是不同类型, 就可以自己写个struct ,
但为了方便就可以使用 c++自带的pair , 返回一个pair,其中带有两个值。除了返回值的应用,在一个对象有多个属性的时候 , 一般自己写一个struct ,如果就是两个属性的话,
就可以用pair 进行操作。pair 可以省的自己写一个struct .如果有三个属性的话,
其实也是可以用的pair 的 ,极端的写法 pair <int ,pair<int ,int > >写法极端。(后边的两个 > > 要有空格,否则就会是 >>位移运算符)
文档内容参考:
https://www.cnblogs.com/aiguona/p/7231377.html
* */
typedef pair < string , string > au ; //利用typedef简化其声明
int main ( ) {
int flag ;
string x1 , x2 ;
pair < string , string > p1 ( " a " , " bc " ) ; //创建一个pair对象, 它的两个元素分别为string和string类型, 其中first成员初始化为“a”, 而second成员初始化为“ab”
pair < string , string > p2 ( " a " , " aa " ) ;
au p3 ;
string name ;
name = p1 . second ; //返回1中名为second的数据成员
cout < < p1 . first < < endl ;
cout < < name < < endl ;
flag = p1 < p2 ;
cout < < flag < < endl ; //判断两个pair对象的大小按字典次序
flag = p1 > p2 ;
cout < < flag < < endl ;
//用例 : 8 James
while ( cin > > x1 > > x2 ) {
p3 = make_pair ( x1 , x2 ) ; //生成一个新的pair对象
cout < < p3 . first < < " **** " < < p3 . second < < endl ;
}
return 0 ;
}