#C10175. Find Anagram Pair
Find Anagram Pair
Find Anagram Pair
You are given a list of words. Your task is to determine whether there exists any pair of words that are anagrams of each other. Two words are anagrams if they contain the same characters in a different order.
If an anagram pair is found, output the two words separated by a single space, in the order in which they appear in the input (i.e. the first word encountered and the later word forming the pair). If no anagram pair exists, output 0
.
The letters are case-sensitive and the input does not contain spaces within words.
Note: Your solution must read input from standard input (stdin) and output to standard output (stdout).
inputFormat
The input begins with an integer n representing the number of words. The following n lines each contain a single word.
Example:
4 listen enlist google gooegl
outputFormat
If an anagram pair is found, print the two words separated by a space. Otherwise, print 0
.
Example:
listen enlist## sample
4
listen
enlist
google
gooegl
listen enlist