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).
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Frequency of smallest character in first sentence less than that of second sentence
- 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
- Snake case of a given sentence
- gOOGLE cASE of a given sentence
- Reverse the Sentence using Stack
- Calculate the difficulty of a sentence
- Camel case of a given sentence
- Check if a word is present in a sentence
- Convert the ASCII value sentence to its equivalent string
- Program to replace a word with asterisks in a sentence
- Print longest palindrome word in a sentence
- Program for length of the longest 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 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.
Improved By : AnkitRai01