Practice

Two-Player Dice Match

2025/Oct/Nov·Variant 3·Q10·[15 marks]
HARD2D Arrays

Two players each roll a die four times. Store the rolls in a 2D array NumberGenerated[1:2, 1:4]. Each round, the player with the higher roll scores 1 point (a draw scores nothing).

If the four-round totals are equal, keep reading extra pairs of rolls until one player is higher, then add 2 points to that player.

Output the players in descending order of points: name then points, two lines each.

Input: Two names, eight round rolls (player 1 then player 2, four times), then extra pairs only if needed for a tie-break. Output: Winner name and points, then runner-up name and points.

Example:

Input:  Ana
        Ben
        6
        1
        6
        1
        6
        1
        1
        6
Output: Ana
        3
        Ben
        1

Sample Test Cases

Test 1: Ana wins 3-1, no tie-break
Inputs: Ana, Ben, 6, 1, 6, 1, 6, 1, 1, 6
Expected: Ana 3 Ben 1
Test 2: Tied 1-1 then Ana wins the tie-break
Inputs: Ana, Ben, 3, 3, 4, 2, 2, 4, 5, 5, 3, 3, 6, 2
Expected: Ana 3 Ben 1