A Text Problem
Time limit6sMemory limit512 MB
For each query string, count the positions in T where it occurs with at most one mismatched letter.
- Level
Hard8 of 10
- Topics
- String matching, Hash map, String
- Solved
- No attempts yet
Problem
The string occurs in the string at position with at most one mistake if and only if either occurs in at position , or there exists a string obtained from by replacing the letter at a single position with a different letter such that occurs in at position .
You are given a string and a series of queries. Each query is a string for which you should compute the number of positions at which it occurs in with at most one mistake.
Input
The first line of input contains the number of test cases . The descriptions of the test cases follow.
The first line of each test case contains a string of length between and consisting of lowercase Latin letters: the string . The next line contains one integer : the number of queries. Each of the following lines contains a nonempty string consisting of lowercase Latin letters: a query. The sum of lengths of all queries in a test case is at most .
The sum of lengths of all strings appearing in all test cases (including queries) does not exceed .
Output
For each query, output the number of positions in at which the query occurs with at most one mistake.