#P6727. Word Coverage by Template
Word Coverage by Template
Word Coverage by Template
You are given \(N\) words and \(Q\) templates. Each template is composed of exactly one *
and some lowercase letters. A template is said to cover a word if, by replacing the *
with any lowercase letter, the template becomes exactly the same as the word.
For each template, determine how many words it can cover.
Note: The template and the word must have the same length, and aside from the *
, all characters in the template should match exactly with the corresponding characters in the word.
inputFormat
The input begins with two integers \(N\) and \(Q\) separated by a space. \(N\) is the number of words and \(Q\) is the number of templates.
Next, there are \(N\) lines each containing one word.
Then, \(Q\) lines follow; each line contains a template consisting of exactly one *
and some lowercase letters.
Constraints: \(1 \leq N, Q \leq 10^5\) (for example).
outputFormat
Output \(Q\) lines, where the \(i\)th line contains a single integer representing the number of words that the \(i\)th template can cover.
sample
5 3
apple
ample
apply
maple
aplea
a*ple
*pple
mapl*
2
1
1
</p>