I am trying to write a program that takes a line as input, finds the duplicate words and erase the duplicate words. Finally it will print a line where there are no duplicate words.
For example:
Input: what what what should i i say say
Output: what should i say
Check if i equals to j, too.
When you erase an item, also decrement j, otherwise one of the "what" will be skipped.
Performance tip: init j with i+1, since all previous items have already been checked.