#C187. Replace Words with Synonyms

    ID: 45122 Type: Default 1000ms 256MiB

Replace Words with Synonyms

Replace Words with Synonyms

You are given a text and a collection of synonym pairs. Your task is to replace all occurrences of whole words in the text that exactly match any key in the synonym list with its corresponding synonym. The matching is case sensitive, meaning that words are only replaced if they exactly match the key (without any change in case).

For example, if the text is The quick brown fox jumps over the lazy dog and the synonym pairs are {"quick": "swift", "lazy": "sluggish", "dog": "hound"}, then the output should be The swift brown fox jumps over the sluggish hound.

inputFormat

Input is read from standard input (stdin). The first line contains the text. The second line contains an integer N, the number of synonym pairs. Each of the next N lines contains two strings separated by space: the word to be replaced and its synonym. Only whole words that match exactly should be replaced.

outputFormat

Output the modified text to standard output (stdout).## sample

The quick brown fox jumps over the lazy dog
3
quick swift
lazy sluggish
dog hound
The swift brown fox jumps over the sluggish hound