#P4173. Aged String Matching

    ID: 17420 Type: Default 1000ms 256MiB

Aged String Matching

Aged String Matching

Long ago, when you first learned about string matching, you encountered two strings \(A\) and \(B\) that contained only lowercase letters, with \(A\) having length \(m\) and \(B\) length \(n\). However, time has passed and the strings have "aged" — each of them is now partially damaged. In this problem, \(A\) is treated as the template string.

For each valid position \(i\) in \(B\), consider the substring \(B_i = B[i, i+m-1]\). You are to determine whether it is possible for \(B_i\) to completely match \(A\). The matching criterion is as follows:

For every index \(j\) in \(0 \le j < m\), let \(A[j]\) and \(B_i[j]\) be the characters at the corresponding positions. These characters are considered to match if either:

  • Both characters are exactly the same.
  • Either of the characters is damaged, represented by a '?' character. A damaged character can match any lowercase letter.

Your task is to print "Yes" if the substring \(B_i\) can possibly match \(A\) according to the rule above, and "No" otherwise. Process every valid starting position \(i\) in \(B\) (i.e. all \(i\) such that \(i + m - 1 < n\)).

Note: Although originally the strings only contained lowercase letters, due to aging some characters may have been lost and are represented as a '?' in the input.

inputFormat

The input consists of two lines:

  1. The first line contains the template string \(A\) (which may include the character '?' representing a damaged character).
  2. The second line contains the target string \(B\) (which may also include '?').

It is guaranteed that \(A\) and \(B\) contain only lowercase letters and possibly '?'.

outputFormat

For each valid starting position \(i\) (i.e. \(0 \le i \le n-m\)) in string \(B\), output a single line containing either "Yes" if the substring \(B[i, i+m-1]\) can match \(A\) based on the matching rules, or "No" otherwise.

sample

a?c
aabcc
No

Yes No

</p>