Count of substrings of a string containing another given string as a substring | Function to store all substrings of S ; Stores the substrings of S ; Pick start point in outer loop and lengths of different strings for a given starting point ; Return the array containing substrings of S ; Function to check if a is present in another string ; Check if target is in the str or not ; Function to count the subof S containing T in it as substring ; Store all substrings of S in the array v [ ] ; Store required count of substrings ; Iterate through all the substrings of S ; If T is present in the current substring , then increment the ans ; Print the answer ; Driver code ; Function Call
def subString ( s , n ) : NEW_LINE INDENT v = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT for len in range ( 1 , n - i + 1 ) : NEW_LINE INDENT find = s [ i : i + len ] NEW_LINE v . append ( find ) NEW_LINE DEDENT DEDENT return v NEW_LINE DEDENT def IsPresent ( str , target ) : NEW_LINE INDENT if ( target in str ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return - 1 NEW_LINE DEDENT def countSubstrings ( S , T ) : NEW_LINE INDENT v = subString ( S , len ( S ) ) NEW_LINE ans = 0 NEW_LINE for it in v : NEW_LINE INDENT if ( IsPresent ( it , T ) != - 1 ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " dabc " NEW_LINE T = " ab " NEW_LINE countSubstrings ( S , T ) NEW_LINE DEDENT