Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Jimmy\'s got a lot of friends. However, he likes to play this game he calls \"Du

ID: 3801526 • Letter: J

Question

Jimmy's got a lot of friends. However, he likes to play this game he calls "Duck Duck Boot."

It's a very simple game. He starts behind his best friend and walks around his circle of gathered

friends in a clockwise direction and to each friend (beginning with his best friend) either yells

"Duck" and swings, or he gives them the boot. If he gives them the boot they become agitated

and then they never talk to Jimmy again (note that this also means they immediately leave the

circle and are no longer a part of the game). After calling “Duck” or after booting his friend

Jimmy will continue from where he is in the circle. He will not start over from his best friend’s

position. Now, to be fair Jimmy has decided that there must be at least one “Duck” before a

boot.

The Problem:

Jimmy's mom is very concerned (she seems to recall that his birthday might be coming up) and

she wants to know if Jimmy will have any friends after he finishes playing this game. She has

hired you to figure out how many friends he will have after he finishes playing this game.

The Input:

The first line will contain a positive integer, g, indicating the number of games Jimmy's mom

wants you to check.

For each game, there will be a line containing a single integer, f (f > 0), which represents the

number of friends that Jimmy has before he starts playing the game (the first friend in the list is

Jimmy's best friend). Each of the following f lines will contain one of his friend's names (up to

20 letters) in the order that they stand in the circle (clockwise order). All of Jimmy’s friends will

have a unique name and will contain only one capital letter at the beginning of his/her name (the

rest of the letters will be lowercase). On the next line there is an integer, r (0 < r 2000), and an

integer, d (0 < d 2000), separated by a single space where r represents the number of rounds

that Jimmy plays with this group of friends (note that if he has no friends left he stops playing)

and d represents the number of times he says "Duck" before he gives someone the boot. Jimmy

is a repetitive boy and once he picks the number of times within a game that he’s going to say

duck before he says boot he will always stick with it.

The Output:

For each game, determine how many friends Jimmy has left after he finishes the last round of

"Duck Duck Boot". Begin the output for each game with a header "Game i:" where i begins with

1 and increases for each game. After this print the list of Jimmy's remaining friends, one per line

by itself (no leading or trailing spaces), in alphabetical order. If Jimmy has no friends left at the

end of the game output "Jimmy has friends no more." After each game output a blank line.

20

Sample Input:

2

3

Bob

Cody

John

2 2

8

Carol

Casey

Nick

Kirsten

Ben

Bo

Billy

Heather

3 4

Sample Output:

Game 1:

Cody

Game 2:

Billy

Bo

Carol

Kirsten

Nick

NEEDED IN C LANGUAGE!!

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
   int num_games,t=1;
   scanf("%d",&num_games);
   while(num_games--) {
       int friends;
       scanf("%d",&friends);

       char str[21];
       char arr[friends][21];

       for(int i=0;i<friends;++i) {
           scanf("%s",str);
           strcpy(arr[i],str);
       }

       int r,d;
       scanf("%d %d",&r,&d);
       int i=0;

       while(r--) { // this loop plays r rounds of the game
           int k = d;
           while(k--) {
               i++;
               i = i%friends;
           }
           int loc = i;
           while(loc<friends) { // this loop is for deleting the elements i.e agitated friends
               strcpy(arr[loc],arr[loc+1]);
               loc++;
           }
           friends--;
       }


       if(friends==0) {
           printf("Game %d: Jimmy has friends no more. ",t);
           printf(" ");
           t++;
       } else {
           char temp[21];
           printf("Game %d: ",t++);


           for (int i=0;i<friends-1;++i) { // this loop is for sorting the array alphabetically
       for (int j = i + 1;j < friends;++j) {
       if (strcmp(arr[i], arr[j]) > 0) {
       strcpy(temp, arr[i]);
       strcpy(arr[i], arr[j]);
       strcpy(arr[j], temp);
       }
       }
           }

           for(int i=0;i<friends;++i) {
               printf("%s ",arr[i]);
           }
           printf(" ");
       }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote