In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but in order to find the letters that appear in the answer it is necessary to unscramble four words. Your task is to write a program that can unscramble words.
The input contains four parts:
1. a dictionary, which consists of at least one and at most 100 words, one per line;
2. a line containing XXXXXX, which signals the end of the dictionary;
3. one or more scrambled `words' that you must unscramble, each on a line by itself; and
4. another line containing XXXXXX, which signals the end of the file.
All words, including both dictionary words and scrambled words, consist only of lowercase English letters and will be at least one and at most six characters long. (Note that the sentinel XXXXXX contains uppercase X's.) The dictionary is not necessarily in sorted order, but each word in the dictionary is unique.
For each scrambled word in the input, output an alphabetical list of all dictionary words that can be formed by rearranging the letters in the scrambled word. Each word in this list must appear on a line by itself. If the list is empty (because no dictionary words can be formed), output the line ``NOT A VALID WORD" instead. In either case, output a line containing six asterisks to signal the end of the list.
翻译:
在美国数以百万计的报纸中,有一个文字游戏叫做Jumble。这个游戏的目的是解决一个谜题,但为了找到答案中出现的字母,有必要解读四个单词。你的任务是写一个可以解读四个字的程序。
输入包含四个部分:1、一本由至少1个,至多100个单词组成的字典,一个单词一行;2、一行包含XXXXXX,表示字典的结束;3、一个或多个未解读的单词你需要解读,一行一个;4、另起一行包含XXXXXX,表示文件的结束。所有单词,包括字典单词和未解读单词,仅由小写英文字母组成,长度至少为 1 且最多为 6 个字符。(注意:标记 XXXXXX 包含大写的 X)。字典不一定按排序顺序排列,但字典中的每个单词都是唯一的。
对输入中每个未解读的单词,输出所有字典单词的字母列表,这些单词可以通过重新排列打乱单词中的字母来形成,列表中的每个单词必须单独成行。如果列表是空的(因为无法形成字典单词),输出一行``NOT A VALID WORD" 。在任何一种情况下,输出一行包含六个星号来表示列表的结束。