Possible Duplicate:
Write a function that returns the longest palindrome in a given string
I have a C++ assignment which wants me write a program that finds the longest palindrome in a given text. For example, the text is this: asdqerderdiedasqwertunut, my program should find tunut in the index of 19. However if input is changed into this astunutsaderdiedasqwertunutit should find astunutsa in the index of 0 instead of tunutin index of 22.
So, my problem is this. But I am a beginner at the subject, i know just string class, loops, ifs. It would be great if you could help me on this.
Thanks in advance.
The idea is very simple:
is_palindrome(string)that takes a string, and returnstrueif it is a palindrome andfalseif it is notis_palindrome(string), and pick the longest one among the strings returningtrue.You can further optimize your program by examining longest substrings ahead of shorter ones. If you examine substrings from longest to shortest, you’ll be able to return as soon as you find the first palindrome.