#C1566. String Replacement

    ID: 44785 Type: Default 1000ms 256MiB

String Replacement

String Replacement

You are given a string text and two additional strings: find and replace. Your task is to replace all occurrences of the substring find in text with the substring replace. If the replace string is empty, then the find substring should be deleted from text.

For example, given the input:

  • text = "the quick brown fox jumps over the lazy dog"
  • find = "the"
  • replace = "a"

The output should be: a quick brown fox jumps over a lazy dog.

Note: The problem is to be solved using input from stdin and output to stdout. All occurrences of find must be replaced, and the operation should be performed exactly as specified. In case find does not appear in text, simply output the original text.

In mathematical terms, if we denote the replacement operation by \( R(text, find, replace) \), then for every occurrence of \( find \) in \( text \), it is replaced by \( replace \), i.e.:

\[ R(text, find, replace) = \text{text with all occurrences of } find \text{ replaced by } replace \]

inputFormat

The input consists of three lines:

  1. First line: A non-empty string text.
  2. Second line: A string find which is the substring to be searched in text.
  3. Third line: A string replace which is used to replace occurrences of find. If empty, it indicates deletion.

The input is read from stdin.

outputFormat

Output a single line containing the modified string after replacing all occurrences of find with replace. The output should be written to stdout.

## sample
the quick brown fox jumps over the lazy dog
the
a
a quick brown fox jumps over a lazy dog