304354: CF832B. Petya and Exam

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Petya and Exam

题意翻译

第一行输入所有"好的"字母 第二行输入一个仅包含小写字母、星号和问号的模式字符串s 星号可以匹配任意长的任何字母(包括空串),问号可以匹配一个"好的"字母 第三行输入一个正整数n 之后n行每行输入一个字符串,问这个字符串能否按上述规则和模式字符串匹配

题目描述

It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "\*"). It is known that character "\*" occurs no more than once in the pattern. Also, $ n $ query strings are given, it is required to determine for each of them if the pattern matches it or not. Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning. A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "\*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string. The good letters are given to Petya. All the others are bad.

输入输出格式

输入格式


The first line contains a string with length from $ 1 $ to $ 26 $ consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the pattern — a string $ s $ of lowercase English letters, characters "?" and "\*" ( $ 1<=|s|<=10^{5} $ ). It is guaranteed that character "\*" occurs in $ s $ no more than once. The third line contains integer $ n $ ( $ 1<=n<=10^{5} $ ) — the number of query strings. $ n $ lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string. It is guaranteed that the total length of all query strings is not greater than $ 10^{5} $ .

输出格式


Print $ n $ lines: in the $ i $ -th of them print "YES" if the pattern matches the $ i $ -th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary.

输入输出样例

输入样例 #1

ab
a?a
2
aaa
aab

输出样例 #1

YES
NO

输入样例 #2

abc
a?a?a*
4
abacaba
abaca
apapa
aaaaax

输出样例 #2

NO
YES
NO
YES

说明

In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter. Explanation of the second example. - The first query: "NO", because character "\*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good. - The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "\*" can be replaced with empty string, and the strings will coincide. - The third query: "NO", because characters "?" can't be replaced with bad letters. - The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "\*" can be replaced with a string of bad letters "x".

Input

题意翻译

第一行输入所有"好的"字母 第二行输入一个仅包含小写字母、星号和问号的模式字符串s 星号可以匹配任意长的任何字母(包括空串),问号可以匹配一个"好的"字母 第三行输入一个正整数n 之后n行每行输入一个字符串,问这个字符串能否按上述规则和模式字符串匹配

加入题单

上一题 下一题 算法标签: