|
|
|
|
|
by svat
2978 days ago
|
|
Another reason for shortening code in programming contests (apart from being able to type and edit/iterate faster) is that it helps you avoid errors. For example, in the heat of the moment and under intense time pressure (e.g. you have finally figured out the algorithm to solve the problem, but you have only 13 minutes left to implement it or whatever), it's easy to write code like this: for (int i = 0; i < n; ++i) {
for (int j = 0; i < n; ++j) {
...
instead of what was intended (j < n).So if you have (in your pre-written library of snippets) a macro like #define FOR(i, n) for(int i = 0, _n = n; i < _n; ++i)
then you can write: FOR(i,n) FOR(j,n) {
...
(the _n in the macro is for cases like FOR(i, v.size()) to avoid recomputation) and at least avoid that particular error. Of course other sorts of silly errors are still possible; some examples here: https://www.quora.com/What-is-the-worst-mistake-youve-made-i... |
|
And I don't mean to say the whole thing is bunk. I found some really good info farther into the book, especially about algorithms, which I think will help towards interviewing candidates.