CCO '97 P1 - Palindromes

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 2.0s
Memory limit: 64M

Problem types
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 n (1n100), the number of strings to be tested, followed by n lines each containing one string of characters of up to 25000 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

Copy
1
AHAHJHFYUBNMLOIUYTRERTYUIOLMNBAGWOIS

Sample Output

Copy
BNMLOIUYTRERTYUIOLMNB
21

Comments

There are no comments at the moment.