This post will cover basic I/O and data structures for use in programming competitions.
C++ is an incredibly complex language, but you can be productive and solve constrained problems by ignoring 99% of the language and using the STL.
C++ is the best choice for programming competitions. It is much faster than Java, and if you study well, you will find it is not much more difficult to write than Java.
Make sure the competition you are attending has enabled C++11 compilation.
You can include all STL headers at once by including <bits/stdc++.h>. So, your skeleton program will look something like the following.
If input is given as a file argument:
But, usually you can just read from STDIN.
If it becomes a smaller size, the extra values are destroyed. If it becomes a larger size, either the extra cells will be filled with the provided argument, or in its absence, with the default constructor of the type. Primitive types such as int will be filled with garbage.
Note that these stack operations are efficient and will not cause too much reallocation because vector maintains a reserved amount of memory.
Test for membership by searching for the element.
Remove by erasing the obtained iterator.
Iteration is identical to the vector.
I recommend defining a macro to make working with collections easier.
Here is the example collection:
This is extremely useful for bruteforcing. Make sure the collection is sorted beforehand.
You can use these on vectors as well, but be sure to sort them beforehand.