我不会的题:Phone numbers

iamvc 2003-05-03 12:39:28
Background
In the present world you frequently meet a lot of call numbers and they are going to be longer and longer. You need to remember such a kind of numbers. One method to do it in an easy way is to assign letters to digits as shown in the following picture:

1 ij 2 abc 3 def
4 gh 5 kl 6 mn
7 prs 8 tuv 9 wxy
0 oqz


This way every word or a group of words can be assigned a unique number, so you can remember words instead of call numbers. It is evident that it has its own charm if it is possible to find some simple relationship between the word and the person itself. So you can learn that the call number 941837296 of a chess playing friend of yours can be read as WHITEPAWN, and the call number 2855304 of your favourite teacher is read BULLDOG.
Problem
Write a program to find the shortest sequence of words (i.e. one having the smallest possible number of words) which corresponds to a given number and a given list of words. The correspondence is described by the picture above.
Input
Input contains a series of tests. The first line of each test contains the call number, the transcription of which you have to find. The number consists of at most 100 digits. The second line contains the total number of the words in the dictionary (maximum is 50000). Each of the remaining lines contains one word, which consists of maximally 50 small letters of the English alphabet. The total size of the input file doesn't exceed 300KB. The last line of input file contains call number -1.
Output
Each line of output contains the shortest sequence of words which has been found by your program. The words are separated by single spaces. If there is no solution to the input data, the line contains text `No solution.'. If there are more solutions having the minimum number of words, you can choose any single one of them.
Sample Input
7325189087
5
it
your
reality
real
our
4294967296
5
it
your
reality
real
our
-1


Sample Output
reality our
No solution.

...全文
44 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
fangrk 2003-05-04
  • 打赏
  • 举报
回复
label
iamvc 2003-05-04
  • 打赏
  • 举报
回复
上面的是:输出
iamvc 2003-05-04
  • 打赏
  • 举报
回复
输入的重复可以
总之能运行就好:)
是我的作业的附+题。也是acm上的题(今日才知)、不过acm今天上不去...
yiminggw 2003-05-04
  • 打赏
  • 举报
回复
I can not understand it
fangrk 2003-05-04
  • 打赏
  • 举报
回复
输出可以有重复吗?
Jinglihui 2003-05-03
  • 打赏
  • 举报
回复
My E is very poor!Can't help you!
dhfly 2003-05-03
  • 打赏
  • 举报
回复
看来我也不会了
SwordMan2001 2003-05-03
  • 打赏
  • 举报
回复
a
c
m
ghtsao 2003-05-03
  • 打赏
  • 举报
回复
It's realy difficult. You make me crazy.

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧