#K84297. Substring Pattern Finder
Substring Pattern Finder
Substring Pattern Finder
You are given a main text string T and a pattern string P. Your task is to find and output all starting indices (0-indexed) in T where the pattern P occurs. If the pattern does not occur in the text or if the input conditions are invalid (for example, an empty pattern or text), output an empty line.
More formally, you need to find all indices i such that:
\(T[i : i+|P|] = P\)
where \(|P|\) denotes the length of P.
Note: The matching should be done in a straightforward manner, and overlapping occurrences are allowed.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains the main text string T.
- The second line contains the pattern string P to search for.
outputFormat
Output the starting indices where P occurs in T in ascending order, separated by a single space. If there are no occurrences, output an empty line.
## sampleabracadabra
abra
0 7