#K39687. Group Anagrams
Group Anagrams
Group Anagrams
Given a list of strings, group the anagrams together. Two strings are anagrams if one can be rearranged to form the other. For each group, sort the words in lexicographical order. The groups should be printed in the order in which their first member appears in the input.
Formally, let \( s \) be a string and let \( s_{sorted} \) denote the string obtained by sorting the characters of \( s \) in ascending order. Then two strings \( s \) and \( t \) are anagrams if \( s_{sorted} = t_{sorted} \). Your task is to output each group of anagrams on a separate line.
inputFormat
The first line contains a single integer \( n \) representing the number of strings. Each of the following \( n \) lines contains a single string consisting of lower-case letters only.
outputFormat
For each group of anagrams, output one line containing the words in that group separated by a single space. The words in each group must be sorted in lexicographical order, and the groups must be output in the order of appearance of their first element in the input. If \( n \) is 0, output nothing.
## sample6
eat
tea
tan
ate
nat
bat
ate eat tea
nat tan
bat
</p>