DWITE, October 2011, Problem 5
A palindrome is a word that is the same backwards as it is forwards (e.g. tattarrattat
). Even though most words aren't palindromes, you can always remove letters from the word to make it a palindrome (remember that all words of length or are palindromes). For example, farmer
is not a palindrome, but removing a few letters yields rer
, which is a palindrome.
Your task is to determine the length of the longest palindrome you can get from a word by removing zero or more letters.
The input will contain 5 test cases, each a line with a string consisting of no more than 255 alphanumeric characters (a-z, A-Z, 0-9). There are no spaces.
For each test case, print one line, each a number — the length of the longest palindrome you can get by removing zero or more letters from the corresponding string.
Sample Input
tattarrattat
sounds
cool
Sample Output
12
3
2
Problem Resource: DWITE
Comments