Under construction

Still being built. Things may change

Badugi Poker

Time limit1sMemory limit256 MB

Summary
Given six distinct cards, each with a number 1 to 15 and a color, sort all 15 pairs by the ranking rules and print the winner first.
Level

Medium4 of 10

Topics
Sorting, Implementation, Brute force, Combinatorics
Solved
No attempts yet

Problem

There are 30 playing cards. The front of each card shows a natural number from 1 to 15, and the back is either black or white.

A card is written with its number in hexadecimal and its color as b or w. For example, the 15 with a white back is written as fw.

Cards are paired up two at a time to play a simplified poker game. The ranks are defined as follows.

  1. Consecutive numbers (1 and f are consecutive.)
  2. Equal numbers
  3. Anything else

Within the same rank, further ranking is determined as follows.

  1. The pair with matching colors
  2. The larger high card
  3. The larger low card
  4. The black high card

Comparisons use the ranks above, and the next criterion is consulted only when the previous criterion does not decide the order.

Given 6 distinct cards, print every pair that can be formed from them in rank order. The order of the two cards in a pair follows the order in which the cards are given in the input.

Input

The first line gives 6 arbitrary cards. The cards are separated by ',', and no card is given more than once.

Output

Print every possible card pair in rank order, one per line.

Examples2

  1. Example 1

    Input
    aw,1w,4b,5w,fb,cw
    
    Expected output
    1wfb
    4b5w
    4bfb
    awcw
    5wcw
    1wcw
    aw5w
    aw1w
    1w5w
    fbcw
    awfb
    5wfb
    4bcw
    aw4b
    1w4b
    
  2. Example 2

    Input
    1w,2w,3w,4w,5w,6w
    
    Expected output
    5w6w
    4w5w
    3w4w
    2w3w
    1w2w
    4w6w
    3w6w
    2w6w
    1w6w
    3w5w
    2w5w
    1w5w
    2w4w
    1w4w
    1w3w