Training Site
Sideways banner

Anagrams

Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 64 megabytes
Time limit: 2.0 seconds

Anagrams

The anagrams of a word are all the possible permutations of the letters in that word

Write a program which is given a word and which outputs, one per line, all the anagrams of that word

Use this algorithm

printAnagram (prefix,word)
if word is length 1 print the prefix and the word
Otherwise
    For each letter in the word
        newPrefix 
  • Sample Input 1

    cat
    

    Sample Output 1

    cta
    act
    atc
    tca
    tac