832B.md (3134B)
1 Source: https://codeforces.com/problemset/problem/832/B 2 3 B. Petya and Exam 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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.. 22 23 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. 24 25 Also, *n* query strings are given, it is required to determine for each of them if the pattern matches it or not. 26 27 Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning. 28 29 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. 30 31 The good letters are given to Petya. All the others are bad. 32 33 Input 34 35 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. 36 37 The second line contains the pattern — a string *s* of lowercase English letters, characters "?" and "*" (1 ≤ |*s*| ≤ 105). It is guaranteed that character "*" occurs in *s* no more than once. 38 39 The third line contains integer *n* (1 ≤ *n* ≤ 105) — the number of query strings. 40 41 *n* lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string. 42 43 It is guaranteed that the total length of all query strings is not greater than 105. 44 45 Output 46 47 Print *n* lines: in the *i*-th of them print "YES" if the pattern matches the *i*-th query string, and "NO" otherwise. 48 49 You can choose the case (lower or upper) for each letter arbitrary. 50 51 Examples 52 53 Input 54 55 ``` 56 ab 57 a?a 58 2 59 aaa 60 aab 61 ``` 62 63 Output 64 65 ``` 66 YES 67 NO 68 ``` 69 70 Input 71 72 ``` 73 abc 74 a?a?a* 75 4 76 abacaba 77 abaca 78 apapa 79 aaaaax 80 ``` 81 82 Output 83 84 ``` 85 NO 86 YES 87 NO 88 YES 89 ``` 90 91 Note 92 93 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. 94 95 Explanation of the second example. 96 97 * 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. 98 * 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. 99 * The third query: "NO", because characters "?" can't be replaced with bad letters. 100 * 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".