+ 1

How to display the largest palindrome from a string..

how to display the longest palindrome from a string using simple functions and without string header file..

1st Jan 2017, 5:51 AM
Mohd Sabahat
Mohd Sabahat - avatar
5 Answers
+ 1
bool is_palindrome(string word){ int size= word.size(); bool IsPalin = true; //test if word is a palindrome for(int i=0;i<size/2;i++){ IsPalin = IsPalin && (word[i]==word[size-i-1] ); } return IsPalin; }
2nd Jan 2017, 5:33 PM
Raphael Allali
Raphael Allali - avatar
0
Hello, You can store the string in an array with predefined length. Then you compare the first and the last character, if they are equal you continue with the second and the one before the last. Otherwise you start from the second element of the array
1st Jan 2017, 8:29 AM
Raphael Allali
Raphael Allali - avatar
0
but my question was that we are given a string and in that string there is a substring which may be a palindrome or there can be more than one palindrome and we have to find the longest of those palindrome By the way can you provide me the code .. I am not able to understand it..Raphael
2nd Jan 2017, 5:29 AM
Mohd Sabahat
Mohd Sabahat - avatar
0
I don't think that is the more efficient way but you can start to test if the string is a palindrome. After that you can check for a palindrome of length the length of the string 1: there is only two possibilities. Then you continue by decreasing the size of the palindrome.
2nd Jan 2017, 5:19 PM
Raphael Allali
Raphael Allali - avatar
0
Raphael I'm still not getting it...I am giving an example and I hope now you will be able to make me understand... Ex- user entered a string "racemammacar" here in this example we have two plaindromes 'mam' and 'amma' now we have to find those palindrome and print the longest of the two....plz help me..
8th Jan 2017, 1:36 PM
Mohd Sabahat
Mohd Sabahat - avatar