#C10410. Group Anagrams
Group Anagrams
Group Anagrams
Given a list of strings, your task is to group the anagrams together. Two words are anagrams if they contain the same characters with the same frequency, but possibly in a different order. The input begins with an integer n followed by n strings.
For each group of anagrams, sort the words in lexicographical order and then sort the groups based on the first word in each group. Finally, print each group on a separate line with the words separated by a space.
For example, if the input is:
4 eat tea tan ate
the output should be:
ate eat tea tan
Note: If there is no word (i.e. n = 0), print nothing.
inputFormat
The first line of input contains a single integer n representing the number of strings. Each of the following n lines contains one string.
outputFormat
Print the grouped anagrams, one group per line. Within each group, the words must be sorted in lexicographical order, and the groups must be ordered by the lexicographically smallest word in each group. Words in the same group are separated by a single space. If n is zero, the output should be empty.
## sample4
eat
tea
tan
ate
ate eat tea
tan
</p>