#C6765. Simplifying Text Using Synonym Replacement
Simplifying Text Using Synonym Replacement
Simplifying Text Using Synonym Replacement
Given a dictionary of synonyms and a text, your task is to replace every word in the text that has a corresponding synonym in the dictionary with its synonym. If a word does not have a synonym in the dictionary, leave it unchanged.
The dictionary is provided as a sequence of pairs, where each pair consists of an original word and its synonym. The text is provided as a sequence of words. Your program should output the simplified text as a single line.
The problem can be formally described as follows:
Let \(n\) be the number of dictionary entries and \(m\) be the number of words in the text. For each word \(w\) in the text, if \(w\) appears in the dictionary, replace it with its synonym; otherwise, keep \(w\) unchanged.
inputFormat
The input is read from stdin and has the following format:
<n> <word> <synonym> # repeated n times <m> <word1> <word2> ... <wordm>
Here, \(n\) is the number of dictionary entries, followed by \(n\) lines each containing an original word and its synonym separated by a space. Then, an integer \(m\) is provided which is the number of words in the text. Finally, a single line with \(m\) space-separated words follows.
outputFormat
The output, written to stdout, is a single line representing the simplified text after performing all appropriate synonym replacements.
## sample5
difficult hard
easy simple
complicated complex
smart clever
fast quick
10
this is a difficult test with some complicated and smart questions to answer fast
this is a hard test with some complex and clever questions to answer quick