#K93872. Group Anagrams
Group Anagrams
Group Anagrams
Given a list of strings, your task is to group the strings that are anagrams of each other. Two strings are anagrams if and only if their sorted characters are the same. The order of groups should follow the order of the first occurrence of each anagram key in the input, and the order of strings in each group must be the same as their appearance in the input.
For example, if the input is:
6 eat tea tan ate nat bat
Then there are three groups:
- ["eat", "tea", "ate"]
- ["tan", "nat"]
- ["bat"]
You are required to read input from standard input (stdin) and write the answer to standard output (stdout) following the specified format.
inputFormat
The first line of input contains an integer n, representing the number of strings. The following n lines each contain a single string.
outputFormat
Print the groups of anagrams in the order of their first occurrence. For each group, print the strings on one line separated by a single space. Do not print extra spaces.
## sample6
eat
tea
tan
ate
nat
bat
eat tea ate
tan nat
bat
</p>