From 3017746873c6fb338b491843e4c656866e37d1b0 Mon Sep 17 00:00:00 2001 From: Benjamin Qi Date: Tue, 9 Jun 2020 11:25:25 -0400 Subject: [PATCH] move pair to separate --- content/2_General/6_Debugging.md | 16 ++++----- content/3_Bronze/4_Bronze_Containers.md | 29 +--------------- content/3_Bronze/6_Pairs.md | 33 +++++++++++++++++++ ...e_Simulation.md => 7_Bronze_Simulation.md} | 2 +- ...ronze_Complete.md => 8_Bronze_Complete.md} | 0 content/Bronze_Containers_Old.md | 2 +- 6 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 content/3_Bronze/6_Pairs.md rename content/3_Bronze/{6_Bronze_Simulation.md => 7_Bronze_Simulation.md} (94%) rename content/3_Bronze/{7_Bronze_Complete.md => 8_Bronze_Complete.md} (100%) diff --git a/content/2_General/6_Debugging.md b/content/2_General/6_Debugging.md index 9e3a802..ccc7b5e 100644 --- a/content/2_General/6_Debugging.md +++ b/content/2_General/6_Debugging.md @@ -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. diff --git a/content/3_Bronze/4_Bronze_Containers.md b/content/3_Bronze/4_Bronze_Containers.md index c60c076..d44fb5a 100644 --- a/content/3_Bronze/4_Bronze_Containers.md +++ b/content/3_Bronze/4_Bronze_Containers.md @@ -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 - -using namespace std; - -int main() { - pair myPair = make_pair("Testing", 123); - cout << myPair.first << " " << myPair.second << endl; // Testing 123 - vector> 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 - */ -``` +``` \ No newline at end of file diff --git a/content/3_Bronze/6_Pairs.md b/content/3_Bronze/6_Pairs.md new file mode 100644 index 0000000..4e6c6be --- /dev/null +++ b/content/3_Bronze/6_Pairs.md @@ -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 + +using namespace std; + +int main() { + pair myPair = make_pair("Testing", 123); + cout << myPair.first << " " << myPair.second << endl; // Testing 123 + vector> 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 + */ +``` diff --git a/content/3_Bronze/6_Bronze_Simulation.md b/content/3_Bronze/7_Bronze_Simulation.md similarity index 94% rename from content/3_Bronze/6_Bronze_Simulation.md rename to content/3_Bronze/7_Bronze_Simulation.md index d10eccd..d789a96 100644 --- a/content/3_Bronze/6_Bronze_Simulation.md +++ b/content/3_Bronze/7_Bronze_Simulation.md @@ -2,7 +2,7 @@ slug: /bronze/simulation title: "Simulation" author: Unknown -order: 6 +order: 7 --- See 5 of https://www.overleaf.com/project/5e73f65cde1d010001224d8a diff --git a/content/3_Bronze/7_Bronze_Complete.md b/content/3_Bronze/8_Bronze_Complete.md similarity index 100% rename from content/3_Bronze/7_Bronze_Complete.md rename to content/3_Bronze/8_Bronze_Complete.md diff --git a/content/Bronze_Containers_Old.md b/content/Bronze_Containers_Old.md index ffcd57f..b799c53 100644 --- a/content/Bronze_Containers_Old.md +++ b/content/Bronze_Containers_Old.md @@ -1,5 +1,5 @@ --- -slug: /bronze/containers +slug: ? title: Containers author: Nathan Wang order: 2