#C200. Synonym Substitution
Synonym Substitution
Synonym Substitution
This problem requires you to perform synonym substitution on an input text. In the text, certain words may have synonyms provided in a dictionary, and each word is replaced by one of its synonyms with a given probability.
The substitution is performed word by word. For each word in the input text, if the word appears as a key in the provided synonym dictionary and a random number (between 0 and 1) is less than the given substitution probability, then the word is replaced with one of its synonyms chosen uniformly at random.
For reproducibility, all solution codes must use a fixed seed (42) for the pseudo-random number generator so that the output is deterministic.
The synonym dictionary is provided in JSON format. The input will be read from standard input and the resulting output must be printed to standard output.
inputFormat
The input consists of three lines:
- A string representing the text.
- A JSON-formatted string representing the synonym dictionary. Each key is a word and its value is an array of synonyms.
- A floating-point number representing the substitution probability.
All input is provided via stdin.
outputFormat
Output the text after performing the substitution. The output should be printed to stdout.
## sampleThe quick brown fox jumps over the lazy dog
{"quick": ["fast", "swift"], "brown": ["dark-brown", "chocolate"], "lazy": ["idle", "lethargic"]}
0.0
The quick brown fox jumps over the lazy dog