QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#14741. Wildcard Matching

统计

Most operating system command-line interfaces (CLI) support wildcard matching for filenames for user convenience. The most common wildcards are two: the asterisk ("*"), which can match any sequence of zero or more characters; and the question mark ("?"), which can match exactly one character.

You are required to write a program that, given a pattern and a list of filenames, determines which files can be matched by the pattern.

Input

The first line contains a string consisting of lowercase letters and the aforementioned wildcards. The second line contains an integer $n$, representing the number of files. The following $n$ lines each contain a string consisting only of lowercase letters, representing the list of filenames.

Output

Output $n$ lines, each being "YES" or "NO", indicating whether the corresponding file can be matched by the wildcard pattern.

Data Range

For 30% of the data: * String length does not exceed 100.

For 100% of the data: String length does not exceed 100000. $1 \le n \le 100$. * The number of wildcards does not exceed 10.

Examples

Input 1

*abc?e**e
3
abcee
ppabcqexe
abcdefgee

Output 1

NO
YES
YES

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.