#P1245. Telephone Keypad Word Translation

    ID: 14532 Type: Default 1000ms 256MiB

Telephone Keypad Word Translation

Telephone Keypad Word Translation

You are given a telephone keypad where each digit is associated with a set of letters as follows:

  • $$1 \leftrightarrow \verb!a!,\verb!b!,\verb!c!$$
  • $$2 \leftrightarrow \verb!d!,\verb!e!,\verb!f!$$
  • $$3 \leftrightarrow \verb!g!,\verb!h!,\verb!i!$$
  • $$4 \leftrightarrow \verb!j!,\verb!k!,\verb!l!$$
  • $$5 \leftrightarrow \verb!m!,\verb!n!$$
  • $$6 \leftrightarrow \verb!o!,\verb!p!,\verb!q!$$
  • $$7 \leftrightarrow \verb!r!,\verb!s!,\verb!t!$$
  • $$8 \leftrightarrow \verb!u!,\verb!v!,\verb!w!$$
  • $$9 \leftrightarrow \verb!x!,\verb!y!,\verb!z!$$

You are also given a dictionary (a list of words) and a digit string (password). Your task is to translate the password using the dictionary. A word from the dictionary is a valid translation if and only if:

  • It has the same length as the digit string.
  • For every position i, the letter in the word belongs to the set of letters corresponding to the ith digit in the password.

If there are multiple valid words, output them in the order they appear in the dictionary, separated by a space. If there is no valid word, output No solution.

inputFormat

The input is given in the following format:

<N>
<word1>
<word2>
... 
<wordN>
<digit_string>

Where:

  • N is a positive integer representing the number of words in the dictionary.
  • Each of the following N lines contains a word (composed of lowercase English letters).
  • The last line is the digit string to be translated (each digit is in the range 1 to 9).

outputFormat

If one or more words match the pattern, output them in one line separated by a single space. If no word matches, output No solution.

sample

3
adg
abc
tuv
123
adg