#C2725. Keyword Occurrence Counter
Keyword Occurrence Counter
Keyword Occurrence Counter
You are given a block of text and a list of keywords. Your task is to count how many times each keyword appears in the text. The search should be case-insensitive and should only match whole words.
For example, given the text:
Data science is the future. Many experts believe that data analysis will change the world.
and the keywords:
data science
the output should be:
2 1
Note: When counting, consider words as sequences of alphanumeric characters separated by non-alphanumeric characters. In other words, use a regular expression like \(\verb|\b\w+\b|\) to tokenize the text.
inputFormat
The input is read from stdin and has the following format:
- The first line contains the text string.
- The second line contains an integer \(n\) representing the number of keywords.
- The following \(n\) lines each contain one keyword.
All inputs should be processed in a case-insensitive manner.
outputFormat
Print to stdout a single line containing \(n\) integers. Each integer is the count of the corresponding keyword (in the input order) found in the text. The counts should be separated by a single space.
## sampleData science is the future. Many experts believe that data analysis will change the world.
2
data
science
2 1