#C4219. Keyword Sentence Finder
Keyword Sentence Finder
Keyword Sentence Finder
You are given a document string that consists of multiple sentences. Each sentence ends with one of the punctuation marks: .
, !
, or ?
. You are also given a list of keywords. Your task is to identify and output all sentences that contain at least one of the given keywords as a whole word (case-insensitive).
Formally, let \( S \) be a sentence and \( k \) be a keyword. The sentence \( S \) should be included in the output if there exists a keyword \( k \) such that \( S \) contains \( k \) as a separate word. In regex terms, you may use the pattern \b
around the keyword (i.e., \bkeyword\b
) for matching.
Note: The input should be read from stdin
and the output should be printed to stdout
. Each matching sentence should be printed on a new line in the order of their occurrence in the document. If no sentence matches, print nothing.
inputFormat
The input is given from standard input (stdin
) in the following format:
- The first line contains the document string which may include spaces and punctuation.
- The second line contains an integer n representing the number of keywords.
- The next n lines each contain one keyword.
outputFormat
For each sentence from the document that contains at least one of the keywords (matching whole words in a case-insensitive manner), print the sentence on a new line in the order in which they appear in the document. If there are no matching sentences, output nothing.
## sampleHello world. This is a pen. How are you doing today? Great weather out!
1
pen
This is a pen.