CCC '16 J3 - Hidden Palindrome

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2016 Stage 1, Junior #3

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 Specification

The input will consist of one line, containing a sequence of at least 1 and at most 40 lowercase letters.

Output Specification

Output the total number of letters of the longest palindrome contained in the input word.

Sample Input 1

banana

Output for Sample Input 1

5

Explanation for Output for Sample Input 1

The palindrome anana has 5 letters.

Sample Input 2

abracadabra

Output for Sample Input 2

3

Explanation for Output for Sample Input 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

Output for Sample Input 3

4

Comments


  • -2
    aaronkoolkid  commented on Feb. 15, 2024, 8:39 p.m.

    the fear of palindromes


  • 0
    longcow  commented on Feb. 9, 2024, 6:15 a.m.

    Aibohphobia is a palindrome too


    • -1
      Kiki_Delfin  commented on Feb. 14, 2024, 4:55 p.m.

      What is Aibohphobia?


      • 2
        bernborgess  commented on Feb. 29, 2024, 9:00 p.m.

        Fear of palindromes


    • -4
      Kiki_Delfin  commented on Feb. 12, 2024, 2:44 p.m.

      ????


  • -1
    Kiki_Delfin  commented on Feb. 3, 2024, 12:56 p.m.

    Goddog is a palindrome too


  • 3
    CodingCrab_520  commented on Dec. 20, 2023, 10:40 p.m.

    Racecar is a palindrome too


  • 101
    lele  commented on Dec. 31, 2018, 1:06 a.m.

    Tacocat is a palindrome