Editorial for WC '15 Contest 1 J1 - Do You Know Your Woburn Colours?


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

This is a straightforward task solved using an if..else statement. It tests the competitor's basic abilities in input/output, comparing strings, and simple logic. Given two of three strings in the set of {"RED", "BLUE", "WHITE"}, we are to identify the other one that was not mentioned.

Initially, one may be tempted to try and code for every possible case of the input (there are 6 combinations) by checking the two inputted strings against ways to choose exactly two of the three colours, taking into account the fact that order matters. This is a feasible way to do it. However, it leads to a solution that is more complicated than necessary. Every second matters in a timed contest, so the less code we have to write the better. To simplify the 6 cases to only 3 cases without added complexity, we can just check which colour isn't in the input. That is, if neither of the input strings compare equal to a particular colour, then this colour must be the one we output.


Comments

There are no comments at the moment.