Programming contests

DEIK Regionális Programozó Csapatverseny, gyakorló feladatsor

October 26, 2012 8:00 PM – November 23, 2012 12:00 AM

Bridge Hands

Many games, such as bridge, involve dealing a standard deck of 52 cards to 4 players, so each receives 13 cards. Good players can then play with the hand as it is dealt, but most ordinary players will need to sort it, firstly by suit, and then by rank within suit.

There is no fixed ranking of the suits for this purpose, but it is useful to alternate the colors, so we will presume the following ordering: clubs < diamonds < spades < hearts. (Note that from now on we will use the more conventional C, D, S, H). Within a suit, ace is the highest, so the ordering is 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < A.

The players are usually designated North, South, East, and West, and they sit at the points of the compass they name. One player is designated the dealer and he (or she) deals one card to each player starting with the player on his (her) left hand and proceeding clockwise until he (she) deals the last card to himself (herself).

Write a program that will read in a presentation of a deck of cards, deal them, sort them, and then display the 4 sorted hands in the format shown below.

Input Specification

The input will consist of a series of deals. Each deal will consist of the letter representing the dealer (N, E, S, or W) followed by two lines representing the deck as shown below. The file will be terminated by a line consisting of a single “#”.

Output Specification

Output will consist of a series of sets of four lines, one set for each deal. Each set will consist of four lines displaying the sorted hands, in the order and format shown below. Sets must follow each other immediately, with no blank lines between them.

Sample Input

  1. N
  2. CQDTC4D8S7HTDAH7D2S3D6C6S6D9S4SAD7H2CKH5D3CTS8C9H3C3
  3. DQS9SQDJH8HAS2SKD4H4S5C7SJC8DKC5C2CAHQCJSTH6HKH9D5HJ
  4. #
download as text file

Output for Sample Input

  1. S: C3 C5 C7 CT CJ D9 DT DJ S3 SK H2 H9 HT
  2. W: C2 C4 CK D4 D5 D6 DQ DA S4 S8 ST SJ H8
  3. N: C6 C8 C9 CA D8 S9 SA H4 H5 H6 H7 HJ HA
  4. E: CQ D2 D3 D7 DK S2 S5 S6 S7 SQ H3 HQ HK
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019