PROBLEM STATEMENT
You and your mom are playing a card game against your opponents. The card game
is the following: your opponents choose some cards from a regular deck of 52
cards and give them to your mom. They also tell her a number N. Your mom
arranges the cards she has and gives them to you in some order. Looking at the
cards you receive you have to guess the number your opponents had told your
mom. Your opponents promise that N is between 1 and the factorial of the number
of cards your mom receives, inclusive.
You have 5 seconds to design a strategy and your mom proposes the following
strategy:
- she assigns standard numbers to card denominations: 1 to ace, 11 to jack, 12
to queen, 13 to king and 2-10 to the other denominations in the natural way.
- she assigns an ordering on suits: clubs, diamonds, hearts, spades.
- now she assigns an ordering on the whole deck: card A is less than card B if
the suit of A comes before the suit of B in the ordering, or if A and B are of
the same suit, then card A is less than card B if the number assigned to A is
less than the number assigned to B.
- now the strategy is the following: your mom pictures in her head all
permutations on the received cards and puts these permutations into
lexicographic order with respect to the ordering on the cards described above.
Then she picks the Nth permutation and gives the cards to you in this order.
Your task is, given the String[] cards, describing the cards you receive,
decide what N is. The cards are described in the natural way -- "seven of
hearts" means the seven of hearts, "queen of spades" means the queen of spades,
etc. The exact format is specified below:
- each element of the input String[] represents a single card, and is a
String which is a concatenation of 3 Strings: the first String is one of
{"ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"jack", "queen", "king"}; the second String is " of " (note the spaces); and
the third String is one of {"clubs", "diamonds", "hearts", "spades"}. For
example: "seven of hearts", "queen of spades".
DEFINITION
Class: CardGame
Method: guess
Parameters: String[]
Returns: int
Method signature (be sure your method is public): int guess(String[] cards);
TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:
- cards has between 1 and 10 elements inclusive
- all elements of cards are distinct
- each element of cards is a String which is a concatenation of 3 Strings: the
first String is one of {"ace", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "jack", "queen", "king"}; the second String is " of ";
and the third String is one of {"clubs", "diamonds", "hearts", "spades"}. For
example: "seven of hearts", "queen of spades"
EXAMPLES
1. cards = {"ace of hearts", "two of hearts", "three of hearts", "four of
hearts"} returns 1
2. cards = {"ace of hearts", "two of hearts", "four of hearts", "three of
hearts"} returns 2
3. cards = {"two of spades", "two of hearts", "two of diamonds", "two of
clubs"} returns 24
4. cards = {"ten of clubs", "nine of clubs", "eight of clubs", "seven of
clubs", "six of clubs", "five of clubs", "four of clubs", "three of clubs",
"two of clubs", "ace of clubs"} returns 3628800