#C181. Count Specified Words in a Text

    ID: 45056 Type: Default 1000ms 256MiB

Count Specified Words in a Text

Count Specified Words in a Text

Given a text string and a list of words, your task is to count the occurrences of each specified word within the text.

The matching is case-insensitive, and punctuation is ignored. In other words, if you let \(T\) be the input text and \(W=\{w_1, w_2, \ldots, w_n\}\) be the list of words to count, you need to compute the number of occurrences for each \(w_i\) in \(T\).

For example, if \(T = \texttt{\"Hello world! Programming in Python is fun. Python is amazing.\"}\) and \(W = [\texttt{python}, \texttt{world}, \texttt{amazing}, \texttt{java}]\), then the answer should be \(\{python: 2, world: 1, amazing: 1, java: 0\}\).

inputFormat

The input is provided via standard input (stdin) as follows:

  1. The first line contains the text string \(T\). The text may include letters, digits, spaces, and punctuation.
  2. The second line contains an integer \(N\) specifying the number of words to count.
  3. The following \(N\) lines each contain a single word to count. These words are given in lowercase.

outputFormat

For each of the \(N\) words in the order they were given, output a line containing the word followed by a space and the number of times it appears in the text.

## sample
Hello world! Programming in Python is fun. Python is amazing.
4
python
world
amazing
java
python 2

world 1 amazing 1 java 0

</p>