#C1070. Find Anagram Pairs
Find Anagram Pairs
Find Anagram Pairs
You are given a list of words. Your task is to find all pairs of words such that one word can be rearranged to form the other, i.e. they are anagrams. Two words are anagrams if, after sorting their characters, they become identical. Formally, for two words a and b, they are anagrams if:
\( sorted(a) = sorted(b) \)
For every pair (word1, word2) satisfying the condition where word1 appears before word2 in the input order, print the pair in the same order. Each valid pair should be printed exactly once. If no such pairs exist, output nothing.
Note: The order of pairs should follow the input sequence.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer n, representing the number of words.
- The next n lines each contain a single word.
It is guaranteed that n is non-negative and each word consists of only lowercase letters.
outputFormat
For each pair of anagrams found, output a line containing the two words separated by a single space, following the order they appear in the input.
If no anagram pairs exist, output nothing (i.e. an empty output).
## sample5
listen
silent
enlist
hello
world
listen silent
listen enlist
silent enlist
</p>