Woburn Challenge 1998

Episode 4: GATTACA (oops, wrong movie)

Dr. Evil, having escaped from Austin Powers last time, is trying a new strategy to extort money from mankind. He has decided to clone himself so that he can make his own fleet of Dr. Evil stormtroopers. Then, and only then, can he successfully hold the United Nations for ransom for the princely sum of … 1 million dollars. He hires the best Evil scientists to extract his DNA and then determine its sequence so that they can make clones of him. However, sequencing technology is not very efficient and yields several fragments of Dr. Evil's DNA. If you put all the fragments together, you will get his entire DNA. However, as a consequence of DNA sequencing, the ends of a fragment are sometimes duplicated at the beginning of next fragment. His scientists are now trying to put these fragments together to form the shortest possible sequence. This, they figure, will be Dr. Evil's DNA. (Little did they know that this very same technique resulted in tragic consequences when Mr. Bigglesworth was "cloned" from Chewbacca's DNA). Note that Dr. Evil is not a bacterium and so his DNA is linear (not circular).

Input

A series of at most 10 strings (each with at most 10 characters) representing DNA fragments (one fragment per line). Note that the strings are in some random order and not necessarily in the order in which they appear in the completed DNA. This will be followed by a 0 (zero) to indicate that the input set is over. This will then be followed by more fragments representing a new DNA strand followed by another 0 and so on till the end of the file.

Output

Put the strings together in some order to produce the smallest DNA strand. Output that DNA strand (one per line for each set). In the event that this strand is not unique, you may output any shortest DNA strand.

Sample Input

AC
CCC
CGT
TAC
0
ACCT
CGA
CCTACG
0

Sample Output

TACCCGT
ACCTACGA

Note: the 1st output is not unique

How: (this is just for your own reference - you do not need to output how the fragments fit together)

TAC
 AC
  CCC
    CGT


ACCT
 CCTACG
     CGA

All Submissions
Best Solutions


Point Value: 20 (partial)
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 29, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

It's quiet in here...