As in C ++ Builder, when creating a text editor, write a function that looks for words in the text that occur only once? Code, please ...
- try to write it yourself, it’s useful and interesting, we can only tell the algorithm and tools =) - Gorets
- there is no time .. until tomorrow it is necessary, so I would write A.)) well, tell me .. - katjusha_cher
- Thanks, but I myself am in the first year, and what has been written here says little about it .. - katjusha_cher
2 answers
I remember that we solved this problem on the 1st course, therefore I will offer my solution.
Point 1 is like @gecube . You throw out the second one, but in the third paragraph I would replace the list with a binary tree. In a sim-binary tree, elements are added as usual, except in the case of coincidence of words, for which each element of the tree is supplied with some field that counts the number of occurrences of this word (respectively, a new element is not added).
Then it is very easy to work with this tree. And, accordingly, expand your task.
- Pull out another word from the text
- Look for it in the text. See standard functions for working with strings. It is also useful to read about the functions for working with the text input component. Among them, there may also be a convenient search and / or replacement function.
- If there are more than one entry, go to step 1; otherwise, we first add the word to the list of words that occur once.
Option 2: Remove all unnecessary (punctuation, multiple spaces, etc.). Next, sort the words alphabetically or in any convenient way. Do not forget about the delimiter between words. Then it is enough to go through the sorted array once and compare successive elements. It is clear that the same words when sorting will fall next.