#P8630. [蓝桥杯 2015 国 B] 密文搜索
[蓝桥杯 2015 国 B] 密文搜索
Description
Holmes received a document from Planet X, consisting entirely of lowercase letters.
His assistant provided another document: a list of many passwords of length .
Holmes found that these passwords were shuffled and hidden in the previous document.
Please write a program to search, in the first document, for positions where hidden passwords may appear. You must consider all permutations of each password.
Input Format
The first line contains a string , consisting only of lowercase letters, with length less than .
The next line contains an integer , indicating that there are lines of passwords below, where .
The next lines each contain a string, all consisting of lowercase letters, each of length .
Output Format
Output one integer, representing the total number of matches in of all permutations of the password on each line.
aaaabbbbaabbcccc
2
aaaabbbb
abcabccc
4
Hint
The first password matches times, and the second password matches time, for a total of times.
Time limit: 3 seconds, 512 MB. Lanqiao Cup 2015, 6th National Finals.
Translated by ChatGPT 5
京公网安备 11011102002149号