#K83827. Count Anagram Groups
Count Anagram Groups
Count Anagram Groups
You are given a list of n words, each consisting of the same number of characters. Two words are anagrams if one can be rearranged to form the other. Formally, two strings \( w_1 \) and \( w_2 \) are anagrams if and only if for every character \( c \), the frequency of \( c \) in \( w_1 \) equals the frequency of \( c \) in \( w_2 \).
Your task is to determine the number of distinct anagram groups present in the list. For example, the words "eat", "tea", and "ate" form a single anagram group.
Example:
Input: 6 eat tea tan ate nat bat Output: 3
In the above example, the groups are: {eat, tea, ate}, {tan, nat} and {bat}.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains an integer \( n \) representing the number of words.
- The second line contains \( n \) words separated by spaces. All words have the same length.
outputFormat
Output a single integer to stdout that represents the number of distinct anagram groups.
## sample6
eat tea tan ate nat bat
3