#K35032. Count Query Word Occurrences
Count Query Word Occurrences
Count Query Word Occurrences
Given a string S and a list of query words, your task is to count the number of times each query word appears in S. The matching is case-insensitive and should only count whole word occurrences. In other words, the query word must appear as a complete word, bounded by non-word characters (use \(\\b\) in LaTeX to denote word boundaries).
For example, if S is "Hello world! Hello everyone. Welcome to the world of programming." and the list of queries is ["hello", "world", "everyone", "python"], then the output should be:
2 2 1 0
Implement the solution by reading from standard input (stdin) and writing the result to standard output (stdout). The input format is described below.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains the string S.
- The second line contains an integer Q which denotes the number of query words.
- The next Q lines each contain one query word.
outputFormat
Output a single line with Q integers separated by a space. Each integer represents the count of the corresponding query word in S.
## sampleHello world! Hello everyone. Welcome to the world of programming.
4
hello
world
everyone
python
2 2 1 0