Canadian Computing Competition: 1997 Stage 2, Day 1, Problem 1
A palindrome is a sequence of characters that reads the same forwards and backwards. e.g. RADAR
, MADAMIMADAM
.
You are to write a program which finds the longest palindrome in a given string of characters.
Input
The input will begin with a line containing one positive integer , the number of strings to be tested, followed by lines each containing one string of characters of up to characters in length and terminated with a blank. The input strings will contain upper case letters only.
Output
Your program should output a pair of lines for each test case with the palindrome on the first line and the length of the palindrome on the second.
In the event of a tie for longest, output the palindrome that appears earlier in the string.
Sample Input
1
AHAHJHFYUBNMLOIUYTRERTYUIOLMNBAGWOIS
Sample Output
BNMLOIUYTRERTYUIOLMNB
21
Comments