#K95712. Expand Abbreviations in Text

    ID: 38925 Type: Default 1000ms 256MiB

Expand Abbreviations in Text

Expand Abbreviations in Text

You are given a list of abbreviation pairs and several lines of text. Your task is to replace each occurrence of an abbreviation that appears as a whole word with its corresponding full form.

Each abbreviation replacement should only occur if the abbreviation is matched as a whole word according to the word boundary \(\b\) in \(\LaTeX\) notation.

For example, if Dr is mapped to Doctor, then in the sentence "Dr Smith was here." the abbreviation Dr should be replaced resulting in "Doctor Smith was here.". Note that the matching is case-sensitive.

inputFormat

The input is read from standard input (stdin) and is structured as follows:

  • The first line contains an integer \(n\) representing the number of abbreviation pairs.
  • The next \(n\) lines each contain two strings: the abbreviation and its full form (separated by spaces).
  • The following line contains an integer \(m\) representing the number of text lines.
  • The next \(m\) lines each contain a piece of text in which abbreviations may occur.

outputFormat

For each of the \(m\) lines of text, output the updated text after expanding all abbreviations. Each output line should be printed to standard output (stdout) on a new line.

## sample
1
Dr Doctor
1
Dr Smith was here.
Doctor Smith was here.

</p>