Shortest Palindromes
Background:
A palindrome is a word that is the spelled the same forwards and backwards.
ie, bab, and a are both palindromes, while ab
is not.
Any word that is not already a palindrome can be made into one by attaching
the appropriate letters. ab may not be a palindrome, but by
attaching an a, we get aba which is a palindrome. Note that we
could also attach ba to get abba which is also a palindrome.
There are an infinite number of strings you can attach to get a palindrome.
In this problem, we're interested in the shortest-length string
that gives us the palindrome.
Input:
Each line of input will have one word on it. The word will have no more than
30 characters. No spaces will appear on the line. The word consists
solely of lower case alphabetic characters.
Output:
For each line of input, print out the palindrome that comes from attaching
the shortest length string of letters to the given word. Note that if
the word is already a palindrome, then nothing should be added. Just print
the word out again.
Sample Input:
palin
a
ab
aba
Sample Output:
palinilap
a
aba
aba