Return to the Top of Page, First Page, or Veteran Problem Set.
You are to read in a deck of shuffled cards and then deal out a solitare hand. The input will be the numbers from 1 to 52 in shuffled order (all 52 may not be present, but enough to deal the hand will be present). You are to then output what seven cards would be face up after the Solitare hand is dealt.
Your input will consist of one number per line. The cards in the deck will be terminated by a zero (0). You may have multiple "decks" in a data file. The input file will end with a negative one (-1) as the first card of a new "deck".
Example Input File: (Note: the data file has been arranged into two columns to save space/paper. Process column one first (top to bottom), and then column two. In parentheses beside each number is its value - this will not be in the real file - it is here to clarify numbering).
16 (3 of diamonds) 35 (9 of clubs)
3 (3 of hearts) 0 (end of first deal)
52 (king of spades) 2 (2 of hearts)
27 (ace of clubs) 7 (7 of hearts)
17 (4 of diamonds) 13 (king of hearts)
22 (9 of diamonds) 48 (9 of spades)
50 (jack of spades) 17 (4 of diamonds)
44 (5 of spades) 11 (jack of hearts)
38 (queen of clubs) 20 (7 of diamonds)
8 (8 of hearts) 1 (ace of hearts)
11 (jack of hearts) 5 (5 of hearts)
34 (8 of clubs) 14 (ace of diamonds)
5 (5 of hearts) 46 (7 of spades)
32 (6 of clubs) 16 (3 of diamonds)
30 (4 of clubs) 45 (6 of spades)
39 (king of clubs) 10 (10 of hearts)
36 (10 of clubs) 26 (king of diamonds)
45 (6 of clubs) 24 (jack of diamonds)
46 (7 of spades) 40 (ace of spades)
48 (9 of spades) 44 (5 of spades)
13 (king of hearts) 28 (2 of clubs)
43 (4 of spades) 15 (2 of diamonds)
41 (2 of spades) 37 (jack of clubs)
10 (10 of hearts) 19 (6 of diamonds)
51 (queen of spades) 16 (3 of clubs)
6 (6 of hearts) 49 (10 of spades)
14 (ace of diamonds) 18 (5 of diamonds)
4 (4 of hearts) 41 (2 of spades)
49 (10 of spades) 34 (8 of clubs)
26 (king of diamonds) 35 (9 of clubs)
7 (7 of hearts) 17 (4 of clubs)
42 (3 of spades) 0 (end of second deal)
12 (queen of hearts) -1 (end of data)
The ouput for this example would be:
Game 1: 3 of diamonds, 5 of spades, 6 of clubs, 7 of spades, 2 of spades, 6 of hearts, 4 of hearts
Game 2: 2 of hearts, ace of hearts, 10 of hearts, 2 of clubs, 3 of clubs, 2 of spades, 9 of clubs
NOTE: Spacing around numbers is not critcal in this problem.
EXPLAINATION:
In solitaire you deal seven stacks of cards. Numbering the stacks
from left to right you have the following:
stack stack stack stack stack stack stack
1 2 3 4 5 6 7
Each stack has in it the same number of cards as its stack number (stack
3 has 3 cards in it).
Dealing the stacks from left to right, the leftmost stack without its
required number of cards gets a face up card and all other stacks get
a face down card. This continues until stack 7 has a seventh (face
up) card.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Return to the Top of Page, First Page, or Veteran Problem Set.
Source Code for a Solution to this Problem
#include <stdio.h> #include <string.h> typedef char CRD[20]; CRD deck[53]; void main() { int cards[53]; /* cards being dealt */ int num; /* number of cards that were read in */ int game; /* game number */ strcpy(deck[ 1],"ace of hearts"); strcpy(deck[ 2], "2 of hearts"); strcpy(deck[ 3], "3 of hearts"); strcpy(deck[ 4], "4 of hearts"); strcpy(deck[ 5], "5 of hearts"); strcpy(deck[ 6], "6 of hearts"); strcpy(deck[ 7], "7 of hearts"); strcpy(deck[ 8], "8 of hearts"); strcpy(deck[ 9], "9 of hearts"); strcpy(deck[10], "ten of hearts"); strcpy(deck[11], "jack of hearts"); strcpy(deck[12], "queen of hearts"); strcpy(deck[13], "king of hearts"); strcpy(deck[14], "ace of diamonds"); strcpy(deck[15], "2 of diamonds"); strcpy(deck[16], "3 of diamonds"); strcpy(deck[17], "4 of diamonds"); strcpy(deck[18], "5 of diamonds"); strcpy(deck[19], "6 of diamonds"); strcpy(deck[20], "7 of diamonds"); strcpy(deck[21], "8 of diamonds"); strcpy(deck[22], "9 of diamonds"); strcpy(deck[23], "ten of diamonds"); strcpy(deck[24], "jack of diamonds"); strcpy(deck[25], "queen of diamonds"); strcpy(deck[26], "king of diamonds"); strcpy(deck[27], "ace of clubs"); strcpy(deck[28], "2 of clubs"); strcpy(deck[29], "3 of clubs"); strcpy(deck[30], "4 of clubs"); strcpy(deck[31], "5 of clubs"); strcpy(deck[32], "6 of clubs"); strcpy(deck[33], "7 of clubs"); strcpy(deck[34], "8 of clubs"); strcpy(deck[35], "9 of clubs"); strcpy(deck[36], "ten of clubs"); strcpy(deck[37], "jack of clubs"); strcpy(deck[38], "queen of clubs"); strcpy(deck[39], "king of clubs"); strcpy(deck[40], "ace of spades"); strcpy(deck[41], "2 of spades"); strcpy(deck[42], "3 of spades"); strcpy(deck[43], "4 of spades"); strcpy(deck[44], "5 of spades"); strcpy(deck[45], "6 of spades"); strcpy(deck[46], "7 of spades"); strcpy(deck[47], "8 of sapdes"); strcpy(deck[48], "9 of spades"); strcpy(deck[49], "ten of spades"); strcpy(deck[50], "jack of spades"); strcpy(deck[51], "queen of spades"); strcpy(deck[52], "king of spades"); game = 0; num = 0; scanf("%d", &cards[num]); while (-1 != cards[num]) { /* start a new deal */ game++; while (0 != cards[num]) { /* get each card */ num++; scanf("%d", &cards[num]); /* printf("%d:%d\n",num,cards[num]); */ } /* get each card */ printf("Game %d: ",game); if (num < 28) printf("Not enough cards:\n"); else { /* print out the seven face up cards */ printf("%s, ",deck[cards[0]]); printf("%s, ",deck[cards[7]]); printf("%s, ",deck[cards[13]]); printf("%s, ",deck[cards[18]]); printf("%s, ",deck[cards[22]]); printf("%s, ",deck[cards[25]]); printf("%s\n",deck[cards[27]]); } /* print out the seven face up cards */ num = 0; scanf("%d", &cards[0]); } /* start a new deal */ }
16 3 52 27 17 22 50 44 38 8 11 34 5 32 30 39 36 45 46 48 13 43 41 10 51 6 14 4 49 26 7 42 12 35 0 2 7 13 48 17 11 20 1 5 14 46 16 45 10 26 24 40 44 28 15 37 19 16 49 18 41 34 35 17 0 -1
Return to the Top of Page, First Page, or Veteran Problem Set.
Game 1: 3 of diamonds, 5 of spades, 6 of clubs, 7 of spades, 2 of spades, 6 of hearts, 4 of hearts Game 2: 2 of hearts, ace of hearts, ten of hearts, 2 of clubs, 3 of diamonds, 2 of spades, 9 of clubs
Return to the Top of Page, First Page, or Veteran Problem Set.
52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 0 1 2 3 4 5 6 7 2 3 4 5 6 7 3 4 5 6 7 4 5 6 7 5 6 7 6 7 52 0 -1
Return to the Top of Page, First Page, or Veteran Problem Set.
Game 1: king of spades, 6 of spades, king of clubs, 8 of clubs, 4 of clubs, ace of clubs, queen of diamonds Game 2: ace of hearts, 8 of hearts, ace of diamonds, 6 of diamonds, ten of diamonds, king of diamonds, 2 of clubs Game 3: ace of hearts, ace of hearts, ace of hearts, ace of hearts, ace of hearts, ace of hearts, ace of hearts Game 4: ace of hearts, 2 of hearts, 3 of hearts, 4 of hearts, 5 of hearts, 6 of hearts, king of spades
Return to the Top of Page, First Page, or Veteran Problem Set.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 0 1 2 3 4 5 6 7 2 3 4 5 6 7 3 4 5 6 7 4 5 6 7 5 6 7 6 7 52 0 -1
Return to the Top of Page, First Page, or Veteran Problem Set.
Game 1: ace of hearts, 8 of hearts, ace of diamonds, 6 of diamonds, ten of diamonds, king of diamonds, 2 of clubs Game 2: ace of hearts, ace of hearts, ace of hearts, ace of hearts, ace of hearts, ace of hearts, ace of hearts Game 3: ace of hearts, 2 of hearts, 3 of hearts, 4 of hearts, 5 of hearts, 6 of hearts, king of spades
Return to the Top of Page, First Page, or Veteran Problem Set.
Return to the LSU High School Programming Contest Homepage