Marjorie and John are playing a board game where they take turns picking the largest number available from a sequence. The winner is determined by the highest sum of the picked numbers. Marjorie plays first in the first round, and they alternate who starts.
Table of Contents π
Write a C program to determine the winner of a board game played by Marjorie and John. The players take turns choosing the largest number from a sequence of numbers arranged in a row. The winner is the player with the highest sum of the chosen numbers.
- An integer
T
, the number of rounds (1 β€ T β€ 100). - For each round:
- An integer
N
, the number of numbers in the sequence (1 β€ N β€ 1000). - A sequence of
N
integers, each in the range [0, 1000].
- An integer
- For each round, print the winner's name ("Marjorie" or "John").
- If there is a tie, print "Draw".
5
7
1 2 3 4 5 6 7
3
1 3 2
1
1
1
1
11
5 8 3 10 1 11 2 9 4 7 6
Output:
Marjorie
Draw
Marjorie
John
John
Explanation:
- In round 1, Marjorie picks 7, John picks 6, and so on. Marjorie wins with a higher sum.
- In round 2, both have equal sums, resulting in a draw.
- In round 3, Marjorie wins with a higher sum of selected numbers.
- In round 4, John wins as he collects the higher numbers.
- In round 5, John wins with a higher sum overall.
- The program must include the function:
void round_result(int *board, int n);
- Where
board
is the array of numbers for one round andn
is the number of elements in the array. - This function should print the winner for the round directly. You cannot modify the function prototype.
- Use pointer arithmetic; array subscripting (e.g.,
array[i]
) is not allowed. - Do not use any counter variables (i, j), and avoid using the
[]
operator.
1. Compile the Program:
2. Run the Program:
3. Input Required:
- The number of rounds
T
. - For each round, the number of elements in the sequence
N
, followed by the sequence of numbers.