+ 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..
5 Respostas
+ 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;
}
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
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
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.
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..