Given a sentence str. The problem is to remove all the palindromic words from the given sentence.
Input : str = "Text contains malayalam and level words" Output : This contains and words Input : str = "abc bcd" Output : abc bcd
Approach: One by one extract all the words. Check if the current word is not a palindrome then add it to the final string.
removePalinWords(str, n) Initialize final_str = "", word = "" str = str + " " for i = 0 to n-1 if str[i] != ' ', then word = word + str[i] else if (!(isPalindrome(word)), then final_str += word + " " word = "" return final_str
isPalindrome() function is used to check whether the given string is palindrome or not. Refer this post.
Text contains and words
Time Complexity: O(n).
- Split a sentence into words in C++
- Count palindrome words in a sentence
- Java program to swap first and last characters of words in a sentence
- Remove Duplicate/Repeated words from String
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Check if the given string of words can be formed from words present in the dictionary
- Count words that appear exactly two times in an array of words
- Calculate the difficulty of a sentence
- Snake case of a given sentence
- Camel case of a given sentence
- gOOGLE cASE of a given sentence
- Sums of ASCII values of each word in a sentence
- Program for length of the longest word in a sentence
- Print given sentence into its equivalent ASCII form
- Print longest palindrome word in 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.