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 int[] containing the number of runs scored from each ball, determine how many runs were scored by each of the batsmen. Return this as a int[] containing exactly two elements. The first element is the number of runs scored by the batsman who faced the first ball, and the second is the number of runs scored by the other batsman.

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

0)

{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.

1)

{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.

2)

{1, 0, 0, 0, 1, 4, 2, 1, 2}

Returns: {7, 4 }

3)

{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.