Skip to content

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.

Notifications You must be signed in to change notification settings

C-Coding-Assignments/Board-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Board Game: Marjorie and John 🎲

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 πŸ“–

Task πŸ› οΈ

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.


Input and Output πŸ–₯️

Input

  • 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].

Output

  • For each round, print the winner's name ("Marjorie" or "John").
  • If there is a tie, print "Draw".

Examples πŸ“‹

Example #1

Input:
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.

Requirements βœ”οΈ

  1. The program must include the function:
    • void round_result(int *board, int n);
    • Where board is the array of numbers for one round and n is the number of elements in the array.
    • This function should print the winner for the round directly. You cannot modify the function prototype.
  2. Use pointer arithmetic; array subscripting (e.g., array[i]) is not allowed.
  3. Do not use any counter variables (i, j), and avoid using the [] operator.

Usage πŸš€

1. Compile the Program:

gcc -o board_game board_game.c

2. Run the Program:

./board_game

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.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages