#C2563. 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 anagrams if they have the same letters in any order, treating uppercase and lowercase letters as the same. For each group, output the words in the group separated by a single space. The groups can be printed in any order.
Note: The grouping is case-insensitive. For example, the words "Listen" and "Silent" are anagrams.
inputFormat
The input is given via standard input (stdin
) and has the following format:
- The first line contains an integer T denoting the number of test cases.
- For each test case, the first line contains an integer N denoting the number of words.
- The following line contains N words separated by spaces.
You may assume that each word consists of only English letters.
outputFormat
For each test case, output the grouped anagrams. Each group should be printed on a separate line, with the words in the same group separated by a single space. If there are multiple test cases, separate the output of different test cases with a blank line.
The order of groups does not matter.
## sample1
3
Listen Silent Enlist
Listen Silent Enlist
</p>