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
- Make palindromic string non-palindromic by rearranging its letters
- 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
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Palindromic Primes
- Generate all palindromic numbers less than n
- Lexicographically first palindromic string
- Palindromic Selfie Numbers
- Number of palindromic permutations | Set 1
- Longest Non-palindromic substring
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.