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
Benjamin Qi 76e9f36b00 debug
2020-06-09 14:34:04 -04:00

785 B

slug: /bronze/pairs title: Pairs & Tuples author: ? order: 6

A pair is a structure that holds two values, not necessarily of the same type.

(tuple?)

(is this present in Java?)

C++

  • 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

#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
 */