#250. 统计特定子串出现次数
统计特定子串出现次数
Count Specific Substrings
Background
Congcong is currently learning about string processing. He encountered an interesting problem that requires counting the occurrences of a specific substring within a given string.
Problem Description
Given a string, return the count of the number of times that a substring of length appears in the string and also matches the last characters of the string. Note that the substring at the very end of the string itself should not be counted.
Input Format
Input is given from standard input in the following format.
A string .
Output Format
Output is printed to standard output in the following format.
An integer representing the count of qualifying substring occurrences.
Sample
hixxhi
1
xaxxaxaxx
1
axxxaaxx
2
Sample Explanation
For hixxhi, the last two characters of the string are "hi". The substring "hi" appears twice in the string: once at the beginning and once at the end. According to the rule, the "hi" at the end is not counted, so only the "hi" at the beginning is counted, resulting in .
For xaxxaxaxx, the last two characters of the string are "xx". The substring "xx" appears twice in the string: at index (xa**xx**axaxx) and at index (xaxxax**xx**). The "xx" at the end (index ) is not counted, so only the one at index is counted, resulting in .
For axxxaaxx, the last two characters of the string are "xx". The substring "xx" appears three times in the string: at index (ax**xx**aaxx), at index (axx**xx**aaxx), and at index (axxxaa**xx**). According to the rule, the "xx" at the end (index ) is not counted, so only the first two are counted, resulting in .
Constraints
The length of the string is between and .