move pair to separate

This commit is contained in:
Benjamin Qi 2020-06-09 11:25:25 -04:00
parent 66ce926ba9
commit 3017746873
6 changed files with 44 additions and 38 deletions

View file

@ -41,9 +41,9 @@ According to [this comment](https://codeforces.com/blog/entry/60999?#comment-449
## CppIO Template
Although not feasible if you have to write all code from scratch, I find [this](https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/CppIO.h) very helpful. `dbg()` only produces output when `-DLOCAL` is included as part of the compilation command.
Although not feasible if you have to write all code from scratch, I find [this template](https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/CppIO.h) very helpful for simplifying input / output / debug output. Note that `dbg()` only produces debug output when `-DLOCAL` is included as part of the compilation command, so you don't need to comment out those lines before submitting.
(add examples of usage)
[Examples - Debug Output](https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/CppIO_test.cpp)
## Stress Testing
@ -57,18 +57,18 @@ A debugger allows you to pause a code in its execution and see the values as a g
To do this, set a "breakpoint" at a certain line of code. When the code runs to that breakpoint, it will pause and you will be able to inspect all the different variables at that certain instance.
There are two more useful and common operations. Once you are at the breakpoint, you may want to see what happens after the current line is executed. This would be the "Step Over" button that will allow you to move to the next line. Say you are at a line with the following code: ``` dfs(0,-1)```, if you click "step over" the debugger will ignore showing you what happens in this function and go to the next line. If you click "step in", however, you will enter the function and be able to step through that function.
There are two more useful and common operations. Once you are at the breakpoint, you may want to see what happens after the current line is executed. This would be the "Step Over" button that will allow you to move to the next line. Say you are at a line with the following code: `dfs(0,-1)`, if you click "step over" the debugger will ignore showing you what happens in this function and go to the next line. If you click "step in," however, you will enter the function and be able to step through that function.
In essense, a debugger is a tool to "trace code" for you. It is not much different from just printing the values out at various points in your program.
Pros of using a debugger:
-No need to write print statements so you save time
- No need to write print statements so you save time
-You can step through the code in real time
- You can step through the code in real time
Cons of using a debugger:
Cons of using a debugger:
-You cannot see the overall "output" of your program at each stage. For example, if I wanted to see the every single value of ```i``` in the program, I could not using a debugger.
- You cannot see the overall "output" of your program at each stage. For example, if I wanted to see the every single value of `i` in the program, I could not using a debugger.
-Most advanced competitive programmers do not use debuggers; it is quite time inefficient.
- Most advanced competitive programmers do not use debuggers; it is quite time inefficient.

View file

@ -286,31 +286,4 @@ ms.erase(ms.find(9));
cout << ms.count(9) << '\n'; // 2
ms.erase(9);
cout << ms.count(9) << '\n'; // 0
```
## [Pair](http://www.cplusplus.com/reference/utility/pair/pair/)
A structure that holds two values, not necessarily of the same type (not built into java!).
- `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
*/
```
```

View file

@ -0,0 +1,33 @@
---
slug: /bronze/pairs
title: Pairs & Tuples
author: ?
order: 6
---
## [Pair](http://www.cplusplus.com/reference/utility/pair/pair/)
A structure that holds two values, not necessarily of the same type (not built into java!).
- `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
*/
```

View file

@ -2,7 +2,7 @@
slug: /bronze/simulation
title: "Simulation"
author: Unknown
order: 6
order: 7
---
See 5 of https://www.overleaf.com/project/5e73f65cde1d010001224d8a

View file

@ -1,5 +1,5 @@
---
slug: /bronze/containers
slug: ?
title: Containers
author: Nathan Wang
order: 2