#C9283. Highlight Keywords
Highlight Keywords
Highlight Keywords
You are given a text and a list of keywords. Your task is to highlight every occurrence of each keyword in the text by wrapping it with underscores. Specifically, for every occurrence of a keyword kw in the text S, replace it with _kw_
using simple text replacement (i.e. no word boundaries or regex are used).
The input begins with an integer \(T\) denoting the number of test cases. Each test case starts with an integer \(N\) representing the number of keywords, followed by a line containing \(N\) space-separated keywords, and finally a line with the text \(S\) in which the keywords need to be highlighted. For each test case, output the modified text on a new line.
Note: Replacement is done in the order of the keywords provided. This means that if a keyword appears as part of another word, it will still be replaced.
inputFormat
The first line contains a single integer \(T\) (the number of test cases). For each test case, the following three lines are given:
- An integer \(N\) representing the number of keywords.
- A line with \(N\) space-separated keywords.
- A line containing a string \(S\) in which you need to highlight the keywords.
All input is read from standard input (stdin).
outputFormat
For each test case, print the processed string with every occurrence of each keyword replaced with the same keyword wrapped in underscores. Each output should be printed on a separate line. All output is written to standard output (stdout).
## sample1
1
foo
foo is a keyword in this text
_foo_ is a keyword in this text
</p>