WinningRecord
SRM 212 · 2004-09-25 · by legakis
Problem Statement
If a baseball team loses 15 games in a row, and then wins its next 5, there are a number of ways this could be reported. A fan of the team could brag that they have won all 5 of their last 5 games. However, it could also be truthfully said that they have won 5 out of their last 10 games, or only 25% of their last 20 games.
Given a
The
Never consider fewer than 3 games. When considering 7 games (for example), they must be the 7 most recent games, not any 7 from the list. If different numbers of games give the same winning record, choose the larger number of games.
Constraints
- results will contain between 3 and 50 characters, inclusive.
- Each character of results will be either 'W' or 'L'.
"WWWWWLLLLLLLLLLLLLLL"
Returns: { 5, 20 }
This is the example from the problem statement.
"WWWWWW"
Returns: { 6, 6 }
No matter how many games you consider, the team's winning record is 100% and the losing record is 0%.
"LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLW"
Returns: { 50, 3 }
"WLWLWLLWWLWLWWWWWWWLWLLLLLLLLLLLLWWLWLLWWWLLLWLWLW"
Returns: { 19, 33 }
"LWWLWWLWWLLLW"
Returns: { 9, 12 }
Submissions are judged against all 41 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class WinningRecord with a public method vector<int> getBestAndWorst(string games) · 41 test cases · 2 s / 256 MB per case