fork download
  1. //#ezcode
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8. typedef vector<int> vi;
  9. typedef pair<int,int> pii;
  10.  
  11. #define F first
  12. #define S second
  13. #define PB push_back
  14. #define MP make_pair
  15.  
  16. /*long long bin_pow(long long x, long long e) {
  17.   long long k;
  18.   if (e == 0) return 1;
  19.   if (e % 2) return bin_pow(x, e - 1) * x;
  20.   else {
  21.   k = bin_pow(x, e / 2);
  22.   return k * k;
  23.   }
  24. }*/
  25.  
  26. string g;
  27. string s;
  28. int n;
  29. string k;
  30. int t, z, r = 0;
  31. int testy = 0;
  32. int tests = 0;
  33. int testx = 0;
  34.  
  35. int main() {
  36. ios_base::sync_with_stdio(0); cin.tie(0);
  37. //freopen("in.txt", "r", stdin);
  38. //freopen("out.txt", "w", stdout);
  39. cin >> g >> s >> n;
  40. t = s.length();
  41. for (int j = 0; j < n; j++) {
  42. testx = 0;
  43. testy = 0;
  44. cin >> k;
  45. z = k.length();
  46. if (t - z >= 2) {
  47. cout << "NO" << '\n';
  48. continue;
  49. }
  50. r = 0;
  51. for (int i = 0; i < t; i++) {
  52. if (s[i] == '?') {
  53. for (auto q : g) {
  54. if (q == k[r]) {
  55. testy++;
  56. break;
  57. }
  58. }
  59. if (testy == 0) {
  60. cout << "NO" << '\n';
  61. testx++;
  62. break;
  63. }
  64. }
  65. else if (s[i] == '*') {
  66. for (int e = r; e < r + z - t + 1; e++) {
  67. for (auto q : g) {
  68. if (q == k[e]) {
  69. cout << "NO" << '\n';
  70. testx++;
  71. break;
  72. }
  73. }
  74. if (testx) break;
  75. }
  76. r += z - t;
  77. if (testx) break;
  78. }
  79. else if (s[i] != k[r]) {
  80. cout << "NO" << '\n';
  81. testx++;
  82. break;
  83. }
  84. r++;
  85. }
  86. if (testx == 0) cout << "YES" << '\n';
  87. }
  88. return 0;
  89. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty