#K58157. Standalone Word Replacement
Standalone Word Replacement
Standalone Word Replacement
You are given a text string, a target word, and a replacement word. Your task is to replace every occurrence of the target word in the text provided it is a standalone word (i.e. it exactly matches and is separated from other words by whitespace) with the replacement word.
Note: If the target word appears as a substring of a larger word, it should not be replaced.
For instance, in the text:
( \text{The cat sat on the catwalk} )
only the isolated occurrence of "cat" (i.e. the word on its own) should be replaced, while "catwalk" remains unchanged.
</p>inputFormat
The input is provided via standard input (stdin) and consists of three lines:
- The first line contains the text string.
- The second line contains the target word.
- The third line contains the replacement word.
All strings may contain spaces.
outputFormat
Output the modified text string to standard output (stdout) after performing the replacement.
## sampleThe cat sat on the catwalk
cat
dog
The dog sat on the catwalk