No.832 Practicing Mahjong
タグ : / 解いたユーザー数 107
作問者 :
bellangeldindon
/ テスター :
37zigen
Problem Statement
Maho loves mahjong.
However, as an eternal beginner, she always commits a chombo (a penalty for an illegal play) at least once a day.
Today, after finally reaching tenpai with a chinitsu (single-suit) hand, she discarded the tile she had drawn and committed a furiten chombo.
Not wanting to lose at mahjong any more, Maho has decided to make a program that determines the winning tiles of a given chinitsu tenpai hand (a hand that can win with one more tile).
To make Maho even stronger, please help her write the program.
[Mahjong rules needed to solve this problem]
・Real mahjong uses 136 tiles of 34 kinds, but this problem uses only 36 tiles of 9 kinds. Each of these tiles has a number from 1 to 9 written on it.
・In mahjong, you "win" when, using tiles you drew yourself or tiles discarded by other players, you can form one of the following shapes.
1) AA BBB CCC DDD EEE
(AA → two identical tiles; each of BBB to EEE → three identical tiles, or three tiles with consecutive numbers)
For example, 11 234 345 666 789 is one of the winning hands.
2) FF GG HH II JJ KK LL
(each of FF to LL → two identical tiles, where F to L must be pairwise distinct)
OK→ 11 33 44 66 77 88 99
NG→ 11 11 33 44 77 88 99
・9→1 is not considered to be consecutive numbers.
For example, 444 555 666 77 891 is not a winning shape.
・A mahjong set contains only four copies of each identical tile.
Therefore, in a hand such as 111 222 333 3 444, 3 may look like a winning tile at first glance, but since you are using all four 3 tiles yourself, it is not considered a winning tile.
Input
$S$
$S$ is a string of 13 characters consisting of digits from 1 to 9. It is always a tenpai hand (a hand that can win with one more tile), and each digit appears at most 4 times.
Output
List the numbers of the winning tiles of the given tenpai hand in ascending order, one per line.
Print a newline at the end.
Sample
Sample 1
Input
1112223334478
Output
6 9
Drawing a 6 or a 9 completes a set of three consecutive numbers, and you can win.
Sample 2
Input
1122334455779
Output
9
Drawing a 9 satisfies "winning condition 2" in the rules (called chiitoitsu, or seven pairs), so you can win.
Sample 3
Input
1112223333444
Output
1 2 4 5
As mentioned above, you are using all of the 3 tiles yourself, so 3 is not considered a winning tile.
Sample 4
Input
1113344778899
Output
3 4
You cannot win with a seven pairs shape that uses four copies of a tile, so 1 is not considered a winning tile. This is because it violates the requirement in winning condition 2 that "F, I, J, K, L are pairwise distinct".
Sample 5
Input
1112345678999
Output
1 2 3 4 5 6 7 8 9
This is the tenpai shape called "Junsei Chuuren Poutou" (pure nine gates), and any tile wins.
Sample 6
Input
4232724138131
Output
6 9
This is the same hand as Sample Case 1, but data that has not been sorted, like this, may also be given as input.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。