Problem D - Cryptoquivalence Classes

We create a cryptogram of some text if we replace each occurence of the letter A by one letter of the alphabet, each occurence of the letter B by some other letter of the alphabet, and so on. For example, one cryptogram of "TO BE OR NOT TO BE" is "ZX OI XR AXZ ZX OI". Another cryptogram of the same phrase is "AB CD BE FBA AB CD". More precisely, a cryptogram of some text is the result of applying a function f to each letter of the text, where f is a one-to-one function with domain and range the 26 letters of the (English) alphabet. Let us call two words "cryptoquivalent" if one is a cryptogram of the other. For example, the words moon and iffy are cryptoquivalent, as are space and any five-letter word with distinct letters. The words all and cat, however, are not cryptoquivalent.

The object of this problem is to find the groups of cryptoquivalent words in a text.

INPUT: Text containing words separated by single spaces or carriage returns, using only upper case English letters.

OUTPUT: The same words, organized by placing cryptoquivalent words on the same line of output. The lines of output may be in any order, but the words within a line must appear in the order in which they appear in the input. Each word should appear in the output exactly as many times as it appears in the input. Your output should have no extra lines or spaces.



Scanned and beautified by onTy Toom, onty@acm.org