#C3888. Count Contiguous Substring Occurrences
Count Contiguous Substring Occurrences
Count Contiguous Substring Occurrences
You are given two strings S and P. Your task is to count the number of contiguous substrings in S that exactly match P. The matching is case sensitive and overlapping occurrences are allowed. For example, if S = "aaaa" and P = "aa", the answer is 3 (matches starting at positions 0, 1, and 2).
You can think of this problem mathematically as finding the number of indices i such that:
\(S[i:i+|P|] = P\)
where \(|P|\) represents the length of string P and the substring is taken from \(S\) starting at index \(i\). If P is longer than S, the answer is 0.
inputFormat
The input is provided via standard input (stdin) consisting of two lines:
- The first line contains the string S.
- The second line contains the pattern string P.
Both strings consist of printable characters.
outputFormat
Output a single integer to standard output (stdout) representing the number of contiguous substrings in S that exactly match P.
## sampleabracadabra
abra
2
</p>