PROBLEM LINK:
Author: Aniket Marlapalle
Tester: Harsh Shah
Editorialist: Harsh
DIFFICULTY:
EASY
PREREQUISITES:
Impementation
PROBLEM:
Described a game (similar to Cricket), simulate it and print the score of the batsmen and team.
EXPLANATION:
The problem requires simple implementation of the rules of the given game. Maintain three variables striker (for striker’s score), unstriker (for unstriker’s score) and total (for total score).
If dice number==-1 , print the striker score and total score. Since new striker comes in, initialize striker=0.
For any other number add the dice number to striker’s score and total score. If the number is odd, swap(striker, unstriker). As striker becomes the unstriker and vice versa.
If the dice throw (d) is a multiple of x i.e. d%x==0 then its swap phase and hence swap(striker, unstriker).
Finally print the total score. See the code snippet for any confusions.
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here