#K52552. Anagram Substring Search
Anagram Substring Search
Anagram Substring Search
You are given a string S and Q queries. For each query, determine the number of substrings of S that are anagrams of the query string. Two strings are anagrams if the frequency counts of each character match. Formally, for two strings \(A\) and \(B\) of equal length, \(A\) is an anagram of \(B\) if and only if
[ \forall c,; \text{count}(c, A) = \text{count}(c, B) ]
Your task is to process each query independently and output the corresponding count. The input is read from stdin and the output should be written to stdout.
inputFormat
The input is given in the following format:
S Q query_1 query_2 ... query_Q
Where:
- S: a non-empty string.
- Q: an integer representing the number of queries.
- Each of the next Q lines contains a query string.
outputFormat
Print a single line with Q integers separated by spaces. Each integer is the count of substrings in S which are anagrams of the corresponding query string.
## samplecbaebabacd
1
abc
2
</p>