Short code fragments for tasks that come up again and again during the contest: reading input, splitting lines into pieces, converting between text and numbers, integer and floating-point arithmetic, and printing numbers with a set number of decimal places.

Everything here uses only the standard libraries that come with each language, as required by the rules. The fragments are deliberately small: they are the kind of thing you would find with a quick search, collected in one place so you can spend your time on the problems instead. They are not complete solutions; combine and adapt them for the problem at hand.

Testing with typed input

Many of the fragments read “until the end of the input”. When the input comes from a file (or the judges’ tests), that happens automatically. When you type the input by hand in a console, you signal the end of input with:

Some IDE consoles handle this differently (or not at all). If yours does not, it is often easier to put the sample input in a text file and paste it in, or to redirect it from the command line:

python prob1.py < input1.txt
java Prob1 < input1.txt
prob1.exe < input1.txt