Statistics

Problem Statement for "CricketScores"

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

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

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

  3. {1, 0, 0, 0, 1, 4, 2, 1, 2}

    Returns: {7, 4 }

  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.

  5. {1, 3, 1, 3, 1, 3, 1, 3}

    Returns: {6, 10 }

  6. {0}

    Returns: {0, 0 }

  7. {6}

    Returns: {6, 0 }

  8. {3, 1, 2, 0, 1, 3, 1, 0, 0, 2, 0, 4, 3}

    Returns: {12, 8 }

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

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

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

  12. {1, 0, 0, 0, 1, 4, 2, 1, 2 }

    Returns: {7, 4 }

  13. {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0 }

    Returns: {6, 4 }

  14. {4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4, 1, 4, 6, 4, 6 }

    Returns: {62, 0 }

  15. {1, 3, 1, 3, 1, 3, 1, 3 }

    Returns: {6, 10 }

  16. {1, 4, 1, 2 }

    Returns: {3, 5 }

  17. {0, 0, 0, 0, 0, 1, 1 }

    Returns: {2, 0 }

  18. {3, 3, 3, 3, 3, 3 }

    Returns: {9, 9 }

  19. {3, 0, 0, 0, 1, 4, 2, 1, 2 }

    Returns: {9, 4 }

  20. {6, 6, 6, 6, 6, 6, 6 }

    Returns: {36, 6 }

  21. {0, 0, 0, 0, 0, 2, 1 }

    Returns: {2, 1 }

  22. {0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 }

    Returns: {3, 6 }

  23. {2, 0, 4, 2 }

    Returns: {8, 0 }

  24. {4, 4, 4, 4, 4, 1, 4 }

    Returns: {25, 0 }

  25. {1, 1, 1, 1, 1, 1, 1 }

    Returns: {3, 4 }

  26. {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }

    Returns: {28, 24 }

  27. {1 }

    Returns: {1, 0 }

  28. {3, 1 }

    Returns: {3, 1 }


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: