#P8630. Hidden Passwords in the Data
Hidden Passwords in the Data
Hidden Passwords in the Data
Holmes received a document from X star consisting entirely of lowercase letters. His assistant provided another document containing a list of passwords, each of length \(8\) (i.e. exactly 8 characters).
Holmes discovered that these passwords, when their characters are arbitrarily rearranged, might be hidden inside the first document. Your task is to write a program that searches for all starting positions in the document where a substring (of length \(8\)) is an anagram of any of the given passwords.
Note: The starting positions are 0-indexed.
inputFormat
The input consists of multiple lines:
- The first line contains a string \(S\) made up of only lowercase letters.
- The second line contains an integer \(N\), representing the number of passwords.
- Each of the following \(N\) lines contains a password (a string of exactly \(8\) lowercase letters).
outputFormat
Output a single line containing the starting indices (0-indexed) of all substrings in \(S\) that is an anagram of any of the given passwords. The indices should be printed in increasing order separated by a space. If there is no such substring, output -1.
sample
abcdefghabcdefgh
1
abcdefgh
0 8