DWITE '12 R5 #2 - Copycat SMS

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
DWITE, February 2013, Problem 2

Having heard that you are busy with a project (something about keeping track of time when travelling), your mischievous friends thought that it might be funny to constantly send you text messages in order to distract you. However, you can write a program to retaliate to this lame plan and send a copy of their messages right back! Always playing a one-up, you are also going to repeat every message twice.

While writing the program, you notice that certain words don't have to be repeated twice completely to still contain two copies of it in the message. For example, the word amalgam can be written as "amalgamalgam", since it still contains two copies of the word, while saving 2 characters.

Given a word, determine what your program should output if it is to save characters in this fashion. The trivial solution of merging the entire word doesn't count though; that is, the input of easy results in easyeasy. The input of oo results in ooo which is the shortest overlap without turning into the previously mentioned trivial case.

The input will contain 5 test cases. Each case is a line with a single string S, where 1 \le |S| \le 256, all lowercase letters, possibly separated by spaces.

The output will contain 5 lines of output. Each line is a repeated (but condensed where possible) copy of the input word.

Sample Input

easy case

Sample Output

easy caseasy case

Problem Resource: DWITE

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported


There are no comments at the moment.