#C1151. Group Anagrams

    ID: 40834 Type: Default 1000ms 256MiB

Group Anagrams

Group Anagrams

Given a list of strings, your task is to group the words that are anagrams of each other. Two words are anagrams if one can be rearranged to form the other. For consistency, each group must have its words printed in lexicographical order, and the groups themselves should be sorted according to the lexicographical order of their first word.

Note: If no words are provided, the program should not output anything.

inputFormat

The input is read from standard input (stdin). The first line contains an integer n, the number of words. Each of the following n lines contains a single word.

outputFormat

For each anagram group, output a single line that contains the words in that group in lexicographical order, separated by a single space. The anagram groups should be output in increasing order based on the first word of each group.## sample

6
eat
tea
tan
ate
nat
bat
ate eat tea

bat nat tan

</p>