← 返回 google 的题目列表Validate a Simplified Mahjong Winning Hand
类型:online_judge
Implement a function that determines whether a simplified Mahjong hand is a winning hand.
The hand contains exactly 14 tiles. Each tile is encoded by a two-character string:
the first character is a rank from 1 to 9;
the second character is a suit: m, p, or s.
A hand is winning if and only if its tiles can be partitioned into:
exactly one pair of two identical tiles; and
exactly four melds, where each meld is either:
a triplet of three identical tiles, or
a sequence of three consecutive ranks in the same suit, such as 3m 4m 5m.
Every tile must be used exactly once. Print true or false.
Input Format
One line containing 14 space-separated tile codes.
Output Format
Print true if the hand is winning; otherwise print false.
Example 1
Input:
1m 1m 2m 3m 4m 2p 3p 4p 5s 5s 5s 7s 8s 9s
Output:
true
Example 2
Input:
1m 1m 1m 2m 3m 4m 2p 3p 4p 5s 5s 5s 7s 9s
Output:
false
Constraints
The input always contains 14 numbered-suit tiles.
Each exact tile occurs at most four times.
Example
Input
1m 1m 2m 3m 4m 2p 3p 4p 5s 5s 5s 7s 8s 9s
Output
true