#C14180. Anagram Groups
Anagram Groups
Anagram Groups
Given a list of words, group them into sets where each set consists of words that are anagrams of each other. Two words are anagrams if they contain the same letters with the same frequency. In other words, two words (w_1) and (w_2) are anagrams if (sorted(w_1) = sorted(w_2)). For each group, sort the words in lexicographical order. Then, sort the groups by the lexicographically smallest word in each group, and output each group on a separate line.
inputFormat
The input is given via stdin. The first line contains an integer (n) representing the number of words. The following (n) lines each contain a single word.
outputFormat
Output the anagram groups via stdout. Each line contains one group, with the words in the group separated by a single space. The words in each group must be sorted in lexicographical order, and the groups must be output in increasing order according to the lexicographically smallest word in each group.## sample
6
eat
tea
tan
ate
nat
bat
ate eat tea
bat
nat tan
</p>