#K91227. Counting Word Occurrences

    ID: 37929 Type: Default 1000ms 256MiB

Counting Word Occurrences

Counting Word Occurrences

You are given one or more datasets. In each dataset, you are provided with a list of words and a list of query words. Your task is to count how many times each query word appears in the list of words.

For each dataset, if we denote the list of words as \(W\) and the list of queries as \(Q\), then for each query \(q \in Q\), you must compute:

$$ count(q) = \#\{w \in W \mid w = q\} $$

The input ends when a dataset with zero words is encountered.

inputFormat

The input is read from standard input (stdin) and consists of multiple datasets. For each dataset:

  • The first line contains an integer \(m\), representing the number of words.
  • The following \(m\) lines each contain a word.
  • The next line contains an integer \(q\), representing the number of query words.
  • The following \(q\) lines each contain a query word.

A dataset starting with a zero (i.e. 0) terminates the input.

outputFormat

For each query in each dataset, output the occurrence count on a separate line to standard output (stdout). The counts should be printed sequentially in the order they appear in the input.

## sample
3
apple
banana
apple
2
apple
banana
0
2

1

</p>