Computer Science, asked by lk1815241, 2 months ago

write a C program:
The Hatfield Game Fair is the premier event of its kind for adults interested in some intellectual and cognitive brain games. Exciting games were organized for kids between age group of 8 and 10. One such game was the "Lucky Cards", a simple two-player game, played with a deck of cards. The cards in the deck have these possible names: two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace. The cards labeled jack, queen, king, ace are collectively known as high cards.
The numerical equivalent of the high cards is as given below:
Jack – 11
Queen – 12
King – 13
Ace - 1
Please note here, though Ace has a numerical equivalent value as 1, it is always considered as the top rated card. So it is also included in the list of high cards.

The game organizer selects N cards and places it in the deck faced-down on the table. Player A turns over the top card and places it on a pile; then player B turns over the top card and places it on the same pile. A and B alternate turns until the N cards are exhausted. The game is scored as follows:
if a player turns over an ace that is 1, with at least 4 cards remain to be turned over, and none of the next 4 cards is a high card, that player scores 4 points
if a player turns over a king that is 13, with at least 3 cards remain to be turned over, and none of the next 3 cards is a high card, that player scores 3 points
if a player turns over a queen that is 12, with at least 2 cards remain to be turned over, and none of the next 2 cards is a high card, that player scores 2 points
if a player turns over a jack that is 11, with at least 1 card remains to be turned over, and the next card is not a high card, that player scores 1 point
Write a program to calculate the scores of the two players.

Input Format:
The first line of the input contain an integer N, which corresponds to the number of cards in the deck.
Each of the following N lines will contain an integer that corresponds to the numerical value of the cards that the players turn over. The first line denotes the first card to be turned over; the next line the next card; and so on.

Output Format:
Print the individual scores of the players whenever a player scores in separate new lines.
Print the total score for each player in the last two lines of the output at the end of the game.
Refer sample input and output for formatting specifications.

Sample Input 1:
15
3
2
1
5
6
4
8
11
2
3
2
13
6
10
6

Sample Output 1:
Player A scores 4 point(s)
Player B scores 1 point(s)
Player B scores 3 point(s)
Player A: 4 point(s)
Player B: 4 point(s)

Sample Input 2:
15
3
2
1
5
6
12
8
11
12
3
1
13
6
11
6

Sample Output 2:
Player B scores 1 point(s)
Player A: 0 point(s)
Player B: 1 point(s)

Answers

Answered by dreamrob
3

Program:

#include<stdio.h>

#include<conio.h>

int main()

{

int N;

printf("Enter total number of cards : ");

scanf("%d", &N);

if(N < 1 || N > 52)

{

 printf("Invalid Input");

 return 0;

}

int A[N];

printf("Enter the values on the cards that are turned: \n");

for(int i = 0; i < N; i++)

{

 scanf("%d", &A[i]);

 if(A[i] < 1 || A[i] > 13)

 {

  printf("Invalid Input");

  return 0;

 }

}

int Point_A = 0, Point_B = 0;

for(int i = 0; i < N; i++)

{

 if(i%2 == 0)

 {

  if(A[i] == 1 && A[i+1] < 11 && A[i+1] != 1 && A[i+2] < 11 && A[i+2] != 1 && A[i+3] < 11 && A[i+3] != 1 && A[i+4] < 11 && A[i+4] != 1)

  {

   printf("Player A scores 4 points.\n");

   Point_A = Point_A + 4;

  }

  if(A[i] == 13 && A[i+1] < 11 && A[i+1] != 1 && A[i+2] < 11 && A[i+2] != 1 && A[i+3] < 11 && A[i+3] != 1)

  {

   printf("Player A scores 3 points.\n");

   Point_A = Point_A + 3;

  }

  if(A[i] == 12 && A[i+1] < 11 && A[i+1] != 1 && A[i+2] < 11 && A[i+2] != 1)

  {

   printf("Player A scores 2 points.\n");

   Point_A = Point_A + 2;

  }

  if(A[i] == 11 && A[i+1] < 11 && A[i+1] != 1)

  {

   printf("Player A scores 1 point.\n");

   Point_A = Point_A + 1;

  }

 }

 else

 {

  if(A[i] == 1 && A[i+1] < 11 && A[i+1] != 1 && A[i+2] < 11 && A[i+2] != 1 && A[i+3] < 11 && A[i+3] != 1 && A[i+4] < 11 && A[i+4] != 1)

  {

   printf("Player B scores 4 points.\n");

   Point_B = Point_B + 4;

  }

  if(A[i] == 13 && A[i+1] < 11 && A[i+1] != 1 && A[i+2] < 11 && A[i+2] != 1 && A[i+3] < 11 && A[i+3] != 1)

  {

   printf("Player B scores 3 points.\n");

   Point_B = Point_B + 3;

  }

  if(A[i] == 12 && A[i+1] < 11 && A[i+1] != 1 && A[i+2] < 11 && A[i+2] != 1)

  {

   printf("Player B scores 2 points.\n");

   Point_B = Point_B + 2;

  }

  if(A[i] == 11 && A[i+1] < 11 && A[i+1] != 1)

  {

   printf("Player B scores 1 point.\n");

   Point_B = Point_B + 1;

  }

 }

}

printf("Player A = %d point(s)\n", Point_A);

printf("Player B = %d point(s)", Point_B);

return 0;

}

Output 1:

Enter total number of cards : 15

Enter the values on the cards that are turned:

3

2

1

5

6

4

8

11

2

3

2

13

6

10

6

Player A scores 4 points.

Player B scores 1 point.

Player B scores 3 points.  

Player A = 4 point(s)

Player B = 4 point(s)

Output 2:

Enter total number of cards : 15

Enter the values on the cards that are turned:

3

2

1

5

6

12

8

11

12

3

1

13

6

11

6

Player B scores 1 point.  

Player A = 0 point(s)

Player B = 1 point(s)

Similar questions