题目正文
You are to write a program that has to generate all possible words from a given set of letters.
Example: Given the word “abc”, your program should - by exploring all different combination of the three letters - output the words “abc”, “acb”, “bac”, “bca”, “cab” and “cba”.
In the word taken from the input file, some letters may appear more than once. For a given word, your program should not produce the same word more than once, and the words should be output in alphabetically ascending order.
Input
The input consists of several words. The first line contains a number giving the number of words to follow. Each following line contains one word. A word consists of uppercase or lowercase letters from A to Z. Uppercase and lowercase letters are to be considered different. The length of each word is less than 13.
Output
For each word in the input, the output should contain all different words that can be generated with the letters of the given word. The words generated from the same input word should be output in alphabetically ascending order. An upper case letter goes before the corresponding lower case letter.
翻译
您要编写一个程序,该程序必须从给定的一组字母生成所有可能的单词。
示例:给定“abc”一词,您的程序应该——通过探索三个字母的所有不同组合——输出“abc”、“acb”、“bac”、“bca”、“cab”和“cba”一词。
在从输入文件中提取的单词中,某些字母可能会出现多次。对于给定的单词,您的程序不应多次生成同一单词,并且单词应按字母升序输出。