#C7271. Highlight Word Occurrences
Highlight Word Occurrences
Highlight Word Occurrences
You are given a word and a text. Your task is to highlight all whole-word occurrences of the given word in the text by surrounding them with double angle brackets << >>
.
Specifically, if the word appears in the text (case-insensitive) as a separate word, it should be replaced by itself wrapped inside <>. For example, if the word word occurs in the text, it should become <<word>>
.
Note: A whole-word occurrence means that the matched substring is not a part of a longer word. In regular expression terms, the word should be matched using boundaries (\b
). Also note that the replacement preserves the original casing.
For instance, given the word word and the text:
This is a word in a sentence.
the output should be:
This is a <<word>> in a sentence.
You are required to read the input from stdin
and write the output to stdout
.
inputFormat
The input consists of two lines:
- The first line contains the word to be highlighted.
- The second line contains the text in which to search.
outputFormat
Output a single line, which is the modified text where each whole-word occurrence of the given word is wrapped in double angle brackets (<< >>
).
word
This is a word in a sentence.
This is a <> in a sentence.