UVa 630 - Anagrams (II)

630 - Anagrams (II)

 * http://acm.uva.es/p/v6/630.html

Summary
Given a dictionary of words. Then given a set of words find all its permutation in the dictionary.

Explanation

 * This all comes down to sorting. A permutation will be exactly the same when it is sorted.
 * Keep a list of sorted and unsorted words.

Input
1

8 atol lato microphotographics rata rola tara tola pies tola kola aatr photomicrographics END

Output
Anagrams for: tola 1) atol 2) lato 3) tola Anagrams for: kola No anagrams for: kola Anagrams for: aatr 1) rata 2) tara Anagrams for: photomicrographics 1) microphotographics