#K11961. Group Anagrams
Group Anagrams
Group Anagrams
You are given a list of strings. Your task is to group the anagrams together. Two strings are anagrams if they contain the same characters in a different order.
In this problem, you will be given an integer n representing the number of strings, followed by n lines each containing a string. You need to group the anagrams and output the number of groups followed by each group on a new line. For each group, the words should be sorted in lexicographical order, and the groups themselves should be sorted based on the lexicographically smallest word in each group.
Note: If a string is empty, it is still considered a valid input.
The solution must read from standard input (stdin) and print the result to standard output (stdout).
inputFormat
The first line contains an integer n which denotes the number of strings.
The following n lines each contain a string.
outputFormat
First, print an integer k which is the number of groups of anagrams.
Then print k lines, each containing the strings of one group separated by a single space. The strings in each group must be sorted lexicographically, and the groups must be ordered by the lexicographically smallest string in each group.
## sample6
eat
tea
tan
ate
nat
bat
3
ate eat tea
bat
nat tan
</p>