#K86572. Remove Consecutive Duplicate Words
Remove Consecutive Duplicate Words
Remove Consecutive Duplicate Words
You are given a string containing words separated by spaces. The task is to remove any consecutive duplicate words so that only a single occurrence remains for each group of consecutive identical words.
For example, if the input is "I went to the the store store", the output should be "I went to the store".
Please note that the comparison is case-sensitive: words with different cases are considered distinct. The input string may be empty, in which case the output should also be an empty string.
Input format: A single line read from standard input containing the string.
Output format: Print the processed string to standard output.
The solution should be implemented in multiple languages and must read input from stdin
and produce output to stdout
.
inputFormat
The input consists of a single line containing a string s. The string may include multiple words separated by spaces. It can also be an empty string.
outputFormat
Output the string after removing all consecutive duplicate words. Words that are not consecutive duplicates should remain unchanged.
## sampleI went to the the store store
I went to the store