#K61127. Counting Pattern Occurrences

    ID: 31241 Type: Default 1000ms 256MiB

Counting Pattern Occurrences

Counting Pattern Occurrences

You are given two strings, ( G ) and ( P ). Your task is to determine the number of times the pattern ( P ) appears in the string ( G ) as a substring. Note that the occurrences may overlap. For instance, if ( G = ) "aaaa" and ( P = ) "aa", the pattern occurs 3 times (starting at indices 0, 1, and 2).

inputFormat

The input consists of two lines:

  • The first line contains the string ( G ) (the garden string).
  • The second line contains the string ( P ) (the pattern to search for).

outputFormat

Output a single integer representing the number of times ( P ) appears as a substring in ( G ).## sample

gardenofgardeniasgarden
garden
3