编程介的小学生 2017-02-24 15:06 采纳率: 20.3%
浏览 1002
已采纳

77377

At the risk of its future, International Cellular Phones Corporation (ICPC) invests its resources in developing new mobile phones, which are planned to be equipped with Web browser, mailer, instant messenger, and many other advanced communication tools. Unless members of ICPC can complete this stiff job, it will eventually lose its market share.
You are now requested to help ICPC to develop intriguing text input software for small mobile terminals. As you may know, most phones today have twelve buttons, namely, ten number buttons from "0" to "9" and two special buttons "*" and "#". Although the company is very ambitious, it has decided to follow today's standards and conventions. You should not change the standard button layout, and should also pay attention to the following standard button assignment.

This means that you can only use eight buttons for text input.

Most users of current ICPC phones are rushed enough to grudge wasting time on even a single button press. Your text input software should be economical of users' time so that a single button press is sufficient for each character input. In consequence, for instance, your program should accept a sequence of button presses "77377" and produce the word "press". Similarly, it should translate "77377843288866" into "press the button".

Ummm... It seems impossible to build such text input software since more than one English letter is represented by a digit! For instance, "77377" may represent not only "press" but also any one of 768 (= 4 * 4 * 3 * 4 * 4) character strings. However, we have the good news that the new model of ICPC mobile phones has enough memory to keep a dictionary. You may be able to write a program that filters out false words, i.e., strings not listed in the dictionary.

Input

The input consists of multiple data sets, each of which represents a dictionary and a sequence of button presses in the following format.

n
word1
. . .
wordn
sequence

n in the first line is a positive integer, representing the number of words in the dictionary. The next n lines, each representing a word in the dictionary, only contain lower case letters from 'a' to 'z'. The order of words in the dictionary is arbitrary (not necessarily in the lexicographic order). No words occur more than once in the dictionary. The last line, sequence, is the sequence of button presses, and only contains digit from '2' to '9'.

You may assume that a dictionary has at most one hundred words and that the length of each word is between one and fifty, inclusive. You may also assume that the number of input digits in the sequence is between on the three hundred, inclusive.

A line containing a zero indicates the end of the input.

Output

For each data set, your program should print all sequences that can be represented by the input sequence of button presses. Each sequence should be a sequence of words in the dictionary, and should appear in a single line. Print the lines in lexicographic order.

Two adjacent words in a line should be separated by a single space character and the last word should be followed by a single period ('.').

Following those output lines, your program should also print a terminating line consisting solely of two hyphens ("--"). If there are no corresponding sequences of words, your program should only print the terminating line.

You may assume that for each data set the number of output lines is at most twenty, excluding the terminating line.

Sample Input

5
push
press
the
button
bottom
77377843288866
4
i
am
going
go
42646464
3
a
b
c
333
0

Sample Output

press the button.

i am go go i.

i am going.

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-03 15:45
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算