#C9917. Count Matching Positions with Wildcards

    ID: 54063 Type: Default 1000ms 256MiB

Count Matching Positions with Wildcards

Count Matching Positions with Wildcards

You are given two strings s and t. The string t may contain wildcard characters represented by '?' which can match any single character. Your task is to count the number of positions in s where the pattern t can match as a substring.

Formally, let \( n = \text{len}(s) \) and \( m = \text{len}(t) \). For every index \( i \) (with \( 0 \leq i \leq n-m \)), the substring \( s[i..i+m-1] \) is considered a match if for each \( j \) (\( 0 \leq j < m \)), either \( t[j] = '?' \) or \( s[i+j] = t[j] \).

Output the count of such matching positions.

inputFormat

The input consists of two lines:

  • The first line contains the string s.
  • The second line contains the pattern string t, which may include the wildcard character '?'.

Both strings are non-empty.

outputFormat

Output a single integer representing the number of positions in s where t matches as a substring.

## sample
abcde
?c?
1