#232. 递归计算不重叠子串出现次数

    ID: 232 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatWarmup-2gesp3字符串递归

递归计算不重叠子串出现次数

Recursive Substring Count

Background

In string processing scenarios, we often need to find the number of occurrences of a specific pattern. Sometimes, these patterns cannot overlap, and we want to solve this problem recursively.

Problem Description

Given a string and a non-empty substring sub, compute recursively the number of times that sub appears in the string, without the substrings overlapping.

Input Format

Input is given from Standard Input in the following format.

The first string SS The literal string " " The second string SUBSUB

Output Format

Output to Standard Output in the following format.

An integer representing the number of non-overlapping occurrences of the substring sub in the string.

Sample

catcowcat" "cat
2
catcowcat" "cow
1
catcowcat" "dog
0

Sample Explanation

Sample 1: The string is "catcowcat\