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).
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.
- 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
- Check if the given string of words can be formed from words present in the dictionary
- Longest Palindromic Substring using Palindromic Tree | Set 3
- 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
- Calculate the difficulty of a sentence
- Snake case of a given sentence
- Reverse the Sentence using Stack
- gOOGLE cASE of a given sentence
- Camel case of a given sentence
- Find the word with most anagrams in a given sentence
- Check if a word is present in a sentence
- Print given sentence into its equivalent ASCII form
- Convert the ASCII value sentence to its equivalent string
- 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 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.
Improved By : AnkitRai01