#C177. Replace Whole Word in a Text

    ID: 45011 Type: Default 1000ms 256MiB

Replace Whole Word in a Text

Replace Whole Word in a Text

You are given a text string along with a target word and a replacement word. Your task is to replace all whole-word occurrences of the target word in the text with the replacement word. Note that only complete words should be replaced. For example, if the target is apple, then apples or appletrees should remain unchanged.

The matching is done using word boundaries defined in the regular expression as \(\texttt{\b}\). In other words, the target word is replaced only when it is preceded and followed by a non-word character or is at the beginning or end of the text.

Example:

Input:
The quick brown fox jumps over the lazy dog.
fox
cat

Output: The quick brown cat jumps over the lazy dog.

</p>

inputFormat

The input is read from standard input (stdin) and consists of three lines:

  • The first line contains the text string.
  • The second line contains the target word to be replaced.
  • The third line contains the replacement word.

outputFormat

Output the modified text string to standard output (stdout) after replacing every whole-word occurrence of the target word with the replacement word.

## sample
The quick brown fox jumps over the lazy dog.
fox
cat
The quick brown cat jumps over the lazy dog.