2016 Canadian Computing Competition
Problem J3: Hidden Palindrome
A palindrome is a word which is the same when read forwards as it is when read backwards. For example, mom
and anna
are two palindromes.
A word which has just one letter, such as a
, is also a palindrome.
Given a word, what is the longest palindrome that is contained in the word? That is, what is the longest palindrome that we can obtain, if we are allowed to delete characters from the beginning and/or the end of the string?
Input Format
The input will consist of one line, containing a sequence of at least 1 and at most 40 lowercase letters.
Output Format
Output the total number of letters of the longest palindrome contained in the input word.
Sample Input 1
banana
Sample Output 1
5
Explanation 1
The palindrome anana
has 5 letters.
Sample Input 2
abracadabra
Sample Output 2
3
Explanation 2
The palindromes aca
and ada
have 3 letters, and there are no other palindromes in the input which are longer.
Sample Input 3
abba
Sample Output 3
4
All Submissions
Best Solutions
Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Feb 22, 2016
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
I would also like to point out that printing the input is very much so looked down upon. This is part of the reason why we clip your output (that is, we don't show you the full output).
Here's a hint: you're making an assumption about how palindromes work that isn't true. This is causing you to not even check the longest palindrome.