Problem Statement
In the game of cricket, the goal of the batting team is to score runs. Two batsmen stand at opposite ends of the pitch (a long, narrow rectangle of ground). A member of the opposing team bowls the ball from one end of the pitch towards the batsman at the other end, who hits it (or tries to). The two batsmen then make zero or more runs before the ball is bowled again (each time this happens is called a ball). The batsmen make a run by each running to the other end of the pitch, thus swapping places (this also means that if they make an odd number of runs, then the other batsman will face the next ball - see example 0 for clarification). Although both batsmen run, only the one to whom the ball was bowled is credited with the runs. After every six balls, the direction of bowling is swapped around.
Given a
Definition
- Class:
- CricketScores
- Method:
- totalRuns
- Parameters:
- int[]
- Returns:
- int[]
- Method signature:
- int[] totalRuns(int[] runs)
- (be sure your method is public)
Notes
- If you are familiar with cricket, you may assume that there are no extras or wickets.
Constraints
- runs will contain between 1 and 50 elements, inclusive.
- Each element of runs will be between 0 and 6, inclusive.
Examples
{1, 4, 1, 2}
Returns: {3, 5 }
The first batsman scores 1, so they swap places. The second batsman then scores 4. Since they swap places an even number of times, he also faces the third ball and scores another 1 and they swap back. The first batsman then scores 2, bringing his total to 3.
{0, 0, 0, 0, 0, 0, 1}
Returns: {0, 1 }
The first batsman faces 6 balls without scoring. The bowling direction is swapped, so the second batsman faces the last ball and scores 1 from it.
{1, 0, 0, 0, 1, 4, 2, 1, 2}
Returns: {7, 4 }
{4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 1, 4, 6, 4, 6}
Returns: {62, 0 }
The first batsman scores one at the end of each group of six balls so that he faces every ball.
{1, 3, 1, 3, 1, 3, 1, 3}
Returns: {6, 10 }
{0}
Returns: {0, 0 }
{6}
Returns: {6, 0 }
{3, 1, 2, 0, 1, 3, 1, 0, 0, 2, 0, 4, 3}
Returns: {12, 8 }
{1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2}
Returns: {81, 90 }
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Returns: {0, 0 }
{6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}
Returns: {156, 144 }
{1, 0, 0, 0, 1, 4, 2, 1, 2 }
Returns: {7, 4 }
{1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0 }
Returns: {6, 4 }
{4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 1, 4, 6, 4, 6 }
Returns: {62, 0 }
{1, 3, 1, 3, 1, 3, 1, 3 }
Returns: {6, 10 }
{1, 4, 1, 2 }
Returns: {3, 5 }
{0, 0, 0, 0, 0, 1, 1 }
Returns: {2, 0 }
{3, 3, 3, 3, 3, 3 }
Returns: {9, 9 }
{3, 0, 0, 0, 1, 4, 2, 1, 2 }
Returns: {9, 4 }
{6, 6, 6, 6, 6, 6, 6 }
Returns: {36, 6 }
{0, 0, 0, 0, 0, 2, 1 }
Returns: {2, 1 }
{0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 }
Returns: {3, 6 }
{2, 0, 4, 2 }
Returns: {8, 0 }
{4, 4, 4, 4, 4, 1, 4 }
Returns: {25, 0 }
{1, 1, 1, 1, 1, 1, 1 }
Returns: {3, 4 }
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }
Returns: {28, 24 }
{1 }
Returns: {1, 0 }
{3, 1 }
Returns: {3, 1 }