Problem 56518. Cricket - Report the Result (Part I: Limited Overs)
Given two scalar strings representing the scores for a limited-overs match, return a string reporting the result in the form "TeamName won by n runs/wickets" (runs or wickets as appropriate). The strings will be given in the order the teams batted and will have the form "TeamName r/w" (where r is runs and w is wickets). If a team is all out, their score will be given as just "TeamName r".
For example, "Pakistan 159/8" and "India 160/6" means that Pakistan batted first and the result should be "India won by 4 wickets". But "Chennai Super Kings 192/3" and "Kolkata Knight Riders 165/9" means that CSK batted first and the result should be "Chennai Super Kings won by 27 runs".
Unlike the 2019 World Cup final, you do not need to worry about ties. You can also be grammatically incorrect for a win by 1 wicket or 1 run (ie you can report the result as "... won by 1 wickets", rather than making a special case for "1 wicket").
The strings will always use single spaces between the team name and the score, but team names may be multiple words ("Chennai Super Kings", "South Africa", etc) which will also be separated by single spaces.
res = resultstring("Pakistan 159/8","India 160/6")
res =
"India won by 4 wickets"
res = resultstring("Chennai Super Kings 192/3","Kolkata Knight Riders 165/9")
res =
"Chennai Super Kings won by 27 runs"
Rules for reporting the result:
- If the team batting first has the higher score, they win by n runs (where n is the difference in the score).
- If the team batting second has the higher score, they win by n wickets, where n is the number of wickets they still have in hand - i.e. the number of wickets that have not fallen. (Given that an innings consists of 10 wickets in total, a team that has lost m wickets wins by n = (10 - m) wickets.)
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers24
Suggested Problems
-
Sum of first n terms of a harmonic progression
419 Solvers
-
Back to basics - mean of corner elements of a matrix
416 Solvers
-
1266 Solvers
-
468 Solvers
-
Snow Accumulation and Structural Risks To Residential Properties
127 Solvers
More from this Author22
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!