#C2072. Replace and Count

    ID: 45348 Type: Default 1000ms 256MiB

Replace and Count

Replace and Count

This problem requires you to implement the function replace_and_count which processes a series of replacement queries on an input string.

For each query, you will replace all non-overlapping occurrences of the substring \(P\) with the substring \(R\) in the given string \(S\) and report the number of replacements performed. Note that after a query is processed, the updated string is used for subsequent queries.

Example: Given \(S = \texttt{hellobeautifulworld}\) and a single query replacing "hello" with "hi", the output should be \(1\) because one occurrence of "hello" is replaced.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains the initial string \(S\).
  • The second line contains an integer \(Q\) representing the number of queries.
  • The following \(Q\) lines each contain two space-separated strings \(P\) and \(R\) representing a replacement query.

outputFormat

Print a single line to standard output (stdout) containing \(Q\) integers separated by a space. The \(i\)-th integer represents the number of replacements made when processing the \(i\)-th query.

## sample
hellobeautifulworld
1
hello hi
1

</p>