#P6872. Filename Pattern Matching

    ID: 20079 Type: Default 1000ms 256MiB

Filename Pattern Matching

Filename Pattern Matching

The problem is to determine if a given filename matches a pattern. The pattern is a string containing only lowercase English letters and a single asterisk (*). The asterisk can be replaced by any (possibly empty) string of lowercase letters, so that if the substitution results in the filename, then the filename matches the pattern.

For example, for the pattern a*d:

  • The filename abcd matches because a + bc + d equals abcd.
  • The filename ad matches as the * is replaced by an empty string.
  • The filename anestonestod matches too.
  • The filename bcd does not match.

Your task is to write a program that reads a pattern and several filenames, then outputs whether each filename matches the pattern.

inputFormat

The first line contains a non-empty pattern string consisting of lowercase letters and one asterisk (*). The second line contains an integer n denoting the number of filenames. Each of the following n lines contains a filename consisting of lowercase letters.

outputFormat

For each filename, output a single line with YES if the filename matches the pattern, or NO if it does not.

sample

a*d
3
abcd
ad
bcd
YES

YES NO

</p>