This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/3_Bronze/6_Bronze_Pairs.md

40 lines
785 B
Markdown
Raw Normal View History

2020-06-09 15:25:25 +00:00
---
slug: /bronze/pairs
title: Pairs & Tuples
author: ?
order: 6
---
2020-06-09 18:34:04 +00:00
A **pair** is a structure that holds two values, not necessarily of the same type.
2020-06-09 15:25:25 +00:00
2020-06-09 18:34:04 +00:00
(tuple?)
<!-- END DESCRIPTION -->
(is this present in Java?)
## [C++](http://www.cplusplus.com/reference/utility/pair/pair/)
2020-06-09 15:25:25 +00:00
- `make_pair(a, b)`: Returns a pair with values a, b.
- `pair.first`: The first value of the pair.
- `pair.second`: The second value of the pair.
Example
```cpp
#include <iostream>
using namespace std;
int main() {
pair<string, int> myPair = make_pair("Testing", 123);
cout << myPair.first << " " << myPair.second << endl; // Testing 123
vector<pair<int,int>> v = {{2,4},{1,3},{3,4},{3,1}};
sort(begin(v),end(v)); // {(1, 3), (2, 4), (3, 1), (3, 4)}
}
/* Output
* Testing 123
*/
```