【正文】
。 else if (pairs == 1) printf(Pair)。 else if (three) printf(Three of a kind)。 else if (flush) printf(Flush)。amp。 else if (four) printf(Four of a kind)。amp。 if (num_in_rank[rank] == 2) pairs++。 rank++) { if (num_in_rank[rank] == 4) four = true。 } /* check for 4ofakind, 3ofakind, and pairs */ for (rank = 0。 num_in_rank[NUM_RANKS1] 0) { straight = true。 num_in_rank[0] 0 amp。 } /* check for acelow straight */ if (num_consec == NUM_CARDS 1 amp。 if (num_consec == NUM_CARDS) { straight = true。 num_in_rank[rank] 0。 rank NUM_RANKS amp。 while (num_in_rank[rank] == 0) rank++。 suit++) if (num_in_suit[suit] == NUM_CARDS) flush = true。 /* check for flush */ for (suit = 0。 three = false。 flush = false。 int rank, suit。 determines the * * number of pairs。 cards_read++。 num_in_suit[suit]++。 ignored.\n)。 ignored.\n)。) bad_card = true。) if (ch != 39。 } while ((ch = getchar()) != 39。 break。S39。s39。 break。H39。h39。 break。D39。d39。 break。C39。c39。 } suit_ch = getchar()。 break。A39。a39。 break。K39。k39。 break。Q39。q39。 break。J39。j39。 break。T39。t39。 break。939。 break。839。 break。739。 break。639。 break。539。 break。439。 break。339。 break。239。: exit(EXIT_SUCCESS)。 switch (rank_ch) { case 39。 printf(Enter a card: )。 suit++) num_in_suit[suit] = 0。 } for (suit = 0。 suit NUM_SUITS。 rank++) { num_in_rank[rank] = 0。 for (rank = 0。 bool bad_card。 char ch, rank_ch, suit_ch。 }}/********************************************************** * read_cards: Reads the cards into the external * * variables num_in_rank and num_in_suit。 analyze_hand()。/********************************************************** * main: Calls read_cards, analyze_hand, and print_result * * repeatedly. * **********************************************************/int main(void){ for (。void analyze_hand(void)。int pairs。int num_in_suit[NUM_SUITS]。 printf(\n\n)。 else if (pairs == 1) printf(Pair)。 else if (three) printf(Three of a kind)。 else if (flush) printf(Flush)。amp。 else if (four) printf(Four of a kind)。amp。 break。 break。 break。 hand[card][RANK] == rank)。 } while (card NUM_CARDS amp。 do { run++。 while (card NUM_CARDS) { rank = hand[card][RANK]。 card++) if (hand[card][RANK] + 1 != hand[card+1][RANK]) straight = false。 /* check for straight */ for (card = 0。 card NUM_CARDS。 } } /* check for flush */ suit = hand[0][SUIT]。 hand[card+1][RANK] = rank。 if (hand[card+1][RANK] rank) { hand[card][RANK] = hand[card+1][RANK]。 card++) { rank = hand[card][RANK]。 pass++) for (card = 0。 /* sort cards by rank */ for (pass = 1。 three = false。 flush = true。 stores the results into * * the external variables straight, flush, * * four, three, and pairs. * **********************************************************/void analyze_hand(void){ int rank, suit, card, pass, run。 } }}/********************************************************** * analyze_hand: Determines whether the hand contains a * * straight, a flush, fourofakind, * * and/or threeofakind。 hand[cards_read][SUIT] = suit。 break。 ignored.\n)。amp。 i cards_read。 } duplicate_card = false。 ignored.\n)。) bad_card = true。) if (ch != 39。 } while ((ch = getchar()) != 39。 break。S39。s39。 break。H39。h39。 break。D39。d39。 break。C39。c39。 } suit_ch = getchar()。 break。A39。a39。 break。K39。k39。 break。Q39。q39。 break。J39。j39。 break。T39。t39。 break。939。 break。839。 break。739。 break。639。 break。539。 break。439。 break。339。 break。239。: exit(EXIT_SUCCESS)。 switch (rank_ch) { case 39。 printf(Enter a card: )。 int cards_read = 0。 int i, rank, suit。 }}/********************************************************** * read_cards: Reads the cards into the external variable * * hand。 analyze_hand()。/********************************************************** * main: Calls read_cards, analyze_hand, and print_result * * repeatedly. * **********************************************************/int main(void){ for (。void analyze_hand(void)。int pairs。pb(53) to print 1 and return. Chapter 10Answers to Selected Exercises1. [was 2] (a) a, b, and c are visible.(b) a, and d are visible.(c) a, d, and e are visible.(d) a and f are visible. Answers to Selected Programming Projects3. [was 4] include /* C99 only */include include define NUM_CARDS 5define RANK 0define SUIT 1/* external variables */int hand[NUM_CARDS][2]。pb(26) to print 0 and return, causing pb(13) to print 1 and return, causingpb(6) to print 0 and return, causingpb(3) to print 1 and return, causingpb(1) to print 1 and return, causingpb(0), which finds that 0 is equal to 0, so it returns, causingpb(1), which finds that 1 is not equal to 0, so it calls pb(3), which finds that 3 is not equal to 0, so it calls pb(6), which finds that 6 is not equal to 0, so it calls pb(13), which finds that 13 is not equal to 0, so it calls pb(26), which finds that 26 is not equal to 0, so it calls pb(53) finds that 53 is not equal to 0, so it calls s execution would look like this: + n % 2)。 putchar(39。 return 0。 pb(n)。n)。 printf(Enter a number: )。}19. [was 16] The following program tests the pb function: include void pb(int n)。 i++) result *= i。 for (i = 2。 } return result。 else if