Problem 300

Problem description here.

The regular solution of this problem is to iterate through the entire input string, and to keep the scores for the current games and sets. 

The shortest submitted solution is more or less with the same logic, except with a lot of tricks being used, and the set scores are not saved explicitelly. The C# solution submitted by hsilomedus:


  • "foreach (int r in p)" iterates through the original strings characters and casts them immediatelly to int. The foreach cycle stores the first value of p and iterates throught it, therefore, all the further changes to p are ignored. In this case, p is used to store the output string. (In Java, for (int r:p.getBytes()) can be used)
  • "(r<50?++a;++b) > 3" a combined expression which based on the ASCII code of the character immediatelly increases the current game score and checks if the newly changed is bigger or equals than 4 (the threshold)
  • "(a-b)/2 != 0" - a nice way to check if the absolute difference between a and b is bigger than or equal to 2.