Given a string, we have to remove all duplicate/repeated words from the string.
Input: str = “Geeks for Geeks A Computer Science portal for Geeks”
Output: Geeks for A Computer Science portal
Explanation: here ‘Geeks’ and ‘for’ are duplicate so these words are removed from the string
Input: “Publish your own articles on GeeksforGeeks and share your knowledge with the world”
Output: Publish your own articles on GeeksforGeeks and share knowledge with the world
Explanation: here ‘your’ is the duplicate word so that word is removed from string
We create an empty hash table. Then split given string around spaces. For every word, we first check if it is in hash table or not. If not found in hash table, we print it and store in the hash table.
To split given string into words, we use stringstream in C++.
Geeks for A Computer Science portal
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.
- Check if the given string of words can be formed from words present in the dictionary
- Remove all the palindromic words from the given sentence
- Reverse words in a given string
- Count words in a given string
- Count words present in a string
- Print all funny words in a string
- Shortest substring of a string containing all given words
- Program to reverse words in a given string in C++
- Check if given words are present in a string
- Reverse words in a given String in Python
- Program to extract words from a given String
- Minimum Distance Between Words of a String
- Reverse String according to the number of words
- Reverse middle words of a string
- Reverse words in a given String in Java
- Print words of a string in reverse order
- Check if a two character string can be made using given words
- Java program to print Even length words in a String
- Remove characters from the first string which are present in the second string
- Extract and print words separately from a given Camel Case string
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 : VishwashBhardwaj