Given a string str, the task is to print longest palindrome word present in the string str.
Input : Madam Arora teaches Malayalam
Explanation: The string contains three palindrome words (i.e., Madam, Arora, Malayalam) but the length of Malayalam is greater than the other two.
Input : Welcome to GeeksforGeeks
Output : No Palindrome Word
Explanation:The string does not contain any palindrome word so the output is No Palindrome Word.
- longestPalin() function finds the longest palindrome word by extracting every word of the string and passing it to checkPalin() function. An extra space is added in the original string to extract last word.
- checkPalin() function checks if the word is palindrome. It returns true if word is palindrome else returns false. It makes sure that empty strings are not counted as palindrome as the user may enter more than one spaces in between or at the beginning of the string.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program for length of the longest word in a sentence
- Print each word in a sentence with their corresponding average of ASCII values
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Longest Common Prefix using Word by Word Matching
- Check if a word is present in a sentence
- Find the word with most anagrams in a given sentence
- Program to replace a word with asterisks in a sentence
- Sums of ASCII values of each word in a sentence
- Java program to count the characters in each word in a given sentence
- Count palindrome words in a sentence
- Next word that does not contain a palindrome and has characters from first k
- Longest Possible Chunked Palindrome
- Length of the longest substring that do not contain any palindrome
- Longest palindrome subsequence with O(n) space
- Longest double string from a Palindrome
- Print given sentence into its equivalent ASCII form
- Print last character of each word in a string
- Print the first and last character of each word in a String
- Longest Palindrome in a String formed by concatenating its prefix and suffix
- Print list items containing all characters of a given word
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.