A rare book collector recently discovered a book written in an unfamiliar language that used the same letters as the English language. The book contained a short index, but the ordering of the items in the index was different from what one would expect if the characters were ordered the same way as in the English alphabet. The collector tried to use the index to determine the ordering of the characters (the collating sequence), but gave up in frustration. Your job is to write a program that, given an index in sorted order, will determine the collating sequence.
The input consists of one or more indices. Each index consists of at least one and at most 100 words followed by a line containing a pound sign '#'. No word contains more than 20 characters. The words in an index consist only of lowercase English letters, and are listed in sorted order according to some collating sequence. Not all characters will necessarily appear in an index, but an index will determine a unique ordering among the characters that do appear. For each index, output a single string that specifies the collating sequence for the characters appearing in that index. Each index is a separate problem.
<BOF> xwy zx zxy zxw ywwx # q a # frog forg fgro gorf gfor # <EOF>
xzyw qa rofg
Dr. Eric Shade (eds231f@cnas.smsu.edu)
![]() |
![]() |