#C14277. Non-overlapping Substring Occurrence Counter
Non-overlapping Substring Occurrence Counter
Non-overlapping Substring Occurrence Counter
Given two strings: a main string and a substring, your task is to count the number of non-overlapping occurrences of the substring within the main string.
If the substring is empty, output 0. If the substring does not appear or if it is longer than the main string, the result should be 0.
For example, if the main string is "aaaaa" and the substring is "aa", the correct count is 2, because the overlapping occurrences are not counted multiple times.
The solution requires reading the input from stdin
and writing the output to stdout
as a single integer.
inputFormat
The input consists of two lines:
- The first line contains the main string.
- The second line contains the substring to search for.
outputFormat
Output a single integer on a line representing the number of non-overlapping occurrences of the substring in the main string.
## sampleababababa
aba
2