eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Letter Cubes

Letter Cubes

This problem is based on a \href{http://crpuzzles.com/logic/logic0136.html}{puzzle by Randall L. Whipkey}. In the game of Letter Cubes, there are a set of cubes, with each face of each cube having a letter of the alphabet, such that no letter appears more than once within the entire set. The maximum number of cubes is \textbf{4}, allowing for up to \textbf{24} of the \textbf{26} letters of the alphabet to occur. Words are formed by rearranging and turning the cubes so that the top letters of all the cubes together spell a word. The \textbf{13} words below have been made using a particular set of cubes. \textbf{CLIP} \textbf{CLOG} \textbf{CONE} \textbf{DISH} \textbf{FAZE} \textbf{FURL} \textbf{MARE} \textbf{MOCK} \textbf{QUIP} \textbf{STEW} \textbf{TONY} \textbf{VICE} \textbf{WARD} Only \textbf{23 }distinct letters were used in the above words, so we will tell you the extra information that a \textbf{B} is included on one cube. Can you now determine the letters on each cube? For the above set of words, there is indeed a unique set of cubes. We will state this solution in canonical form as \textbf{ABCHTU DEKLQY FGIMNW OPRSVZ} Note that the letters on each individual cube are stated as a string of characters in alphabetical order, and the four\textbf{6}-letter strings representing the four cubes are also listed in alphabetical order. A simpler example relies on two cubes, forming the following \textbf{11} two-character strings (although the puzzles are more fun when the strings are actual words, they do not need to be): \textbf{PI} \textbf{MU} \textbf{HO} \textbf{WE} \textbf{WO} \textbf{BE} \textbf{MA} \textbf{HI} \textbf{RE} \textbf{AB} \textbf{PY} The only solution for the two cubes forming these strings is \textbf{AEIOUY BHMPRW} The same two cubes could be determined without the last pair \textbf{PY} being listed, as long as you were told that there was a \textbf{Y} on one cube. Your job is to make similar deductions. \InputFile The input will contain from \textbf{1} to \textbf{20} datasets. The first line of each dataset will include a positive integer \textbf{n} (\textbf{6} ≤ \textbf{n} ≤ \textbf{30}) and a character \textbf{c}, described below. The next \textbf{n} lines will each contain a string of uppercase letters. Each string will be the same length, call it \textbf{k}, with \textbf{2} ≤ \textbf{k} ≤ \textbf{4}. Following the last dataset is a line containing only \textbf{0}. Returning to the issue of the special character, \textbf{c}, on the first input line for each dataset, there will be two cases to consider. Recall that the implicit set of \textbf{k} cubes must use \textbf{6*k} distinct letters on their collective faces If all \textbf{6*k} of those letters appear within the set of strings, then the character \textbf{c} on the first line of input is a hyphen, '\textbf{-}'. Otherwise, the strings have been chosen so that only one letter on the cubes does not appear. In this case, the character \textbf{c} on the first line of input will be that undisplayed letter. (For example, the \textbf{B} in our opening puzzle.) \OutputFile There is one line of output for each dataset, containing a \textbf{6}-letter string for each cube, showing the letters on the faces of that cube. Each of those strings should have its letters in alphabetical order, and the set of strings should be given in alphabetical order with respect to each other, with one space between each pair. We have chosen datasets so that each has a unique solution.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
13 B
CLIP
CLOG
CONE
DISH
FAZE
FURL
MARE
MOCK
QUIP
STEW
TONY
VICE
WARD
11 -
PI
MU
HO
WE
WO
BE
MA
HI
RE
AB
PY
10 Y
PI
MU
HO
WE
WO
BE
MA
HI
RE
AB
0
Вихідні дані #1
ABCHTU DEKLQY FGIMNW OPRSVZ
AEIOUY BHMPRW
AEIOUY BHMPRW
Джерело ACM Mid-Central Regional Programming Contest 2013