WINLOSE - Editorial

PROBLEM LINK:

Practice
Contest

Author: Bhushan Khanale
Editorialist: Bhushan Khanale

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

Binary string is provided containing the information on “who has won that specific game”. ‘1’ corresponding to Tanu’s win and ‘0’ corresponding to Manu’s win. There is a special scoring system for the wins and loses. If a player wins a match he is credited with 5 points and if he wins 5 games or more in a row then he is credited with 10 extra points for that particular winning streak and the player losing will have 5 points deducted from his account. The problem is to find the player having most points at the end of all games (end of binary string).

QUICK EXPLANATION:

Data is provided about the winning games of two friends with a specific scoring system. The problem is to find the player who has scored most points at the end of all games.

EXPLANATION:

A simple iteration over all characters of the binary string will be enough to calculate the winner for this problem. If a player wins a game 5 points are added to his account straight away. Now we have to consider the number of consecutive wins too for each of the two players. If a player wins a game then the consecutive winning counter will increase by 1 for him while as for the second player the consecutive winning count will reset to 0. Now we would simply compare the consecutive wins with 5 at every iteration. If the consecutive wins is 5 (which ensures that we are adding the extra points on winning 5 consecutive games) then we will add 10 points to the respective winning person’s account and deduct 5 from the one losing. At last we have to print the winner in terms of “Tanu”, “Manu” and “Draw”.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.