#C13466. Group Anagrams
Group Anagrams
Group Anagrams
You are given a list of words. Your task is to group the words that are anagrams of each other. Two words are considered anagrams if one word's letters can be rearranged to form the other. For each group, use as the key the sorted string of characters from the word (i.e. the anagram signature).
Input Format:
The first line contains an integer n, the number of words. The second line contains n words separated by spaces.
Output Format:
For each unique anagram group, output a single line in the following format:
signature: word1 word2 ...
Here, signature
is the sorted string of characters of the words in that group. The groups should be printed in increasing lexicographical order of their signature, and the words in each group should follow the order of their appearance in the input.
Example:
Input:
6
bat tab tap pat dog god
Output:
abt: bat tab
apt: tap pat
dgo: dog god
inputFormat
The first line contains an integer n representing the number of words. The second line contains n words separated by spaces.
outputFormat
For each anagram group, output a line with the sorted signature (concatenated letters) followed by a colon and then the list of words in that group, separated by spaces. The groups are ordered by their signature in lexicographical order.
## sample6
bat tab tap pat dog god
abt: bat tab
apt: tap pat
dgo: dog god
</p>