Given a string str and the task is to count palindrome words present in the string str.
Input : Madam Arora teaches malayalam Output : 3 The string contains three palindrome words (i.e., Madam, Arora, malayalam) so the count is three. Input : Nitin speaks malayalam Output : 2 The string contains two palindrome words (i.e., Nitin, malayalam) so the count is two.
countPalin() function counts the number of palindrome words 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 check the word palindrome. It returns 1 if word is palindrome else returns 0. 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.
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Frequency of smallest character in first sentence less than that of second sentence
- Count words that appear exactly two times in an array of words
- Java program to swap first and last characters of words in a sentence
- Split a sentence into words in C++
- Remove all the palindromic words from the given sentence
- Print longest palindrome word in a sentence
- Count all palindrome which is square of a palindrome
- Check if the given string of words can be formed from words present in the dictionary
- Palindrome pair in an array of words (or strings)
- Java program to count the characters in each word in a given sentence
- Count words present in a string
- Count the number of words having sum of ASCII values less than and greater than k
- Count of words ending at the given suffix in Java
- Count of words that are present in all the given sentences
- Count words in a given string
- Count of words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of given word
- Sort numbers based on count of letters required to represent them in words
- Check a given sentence for a given set of simple grammer rules
- Calculate the difficulty of a sentence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.