Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. /************************
  2.  **  Solution by daun  **
  3.  ***********************/
  4.  
  5. #include <bits/stdc++.h>
  6.  
  7. using namespace std;
  8.  
  9. const int N = 1e5 + 5;
  10. const int INF = 4127;
  11. const int mod = 475;
  12. string good, shablon;
  13. int n, x = -1;
  14. bool no = false, zv = false, yes = false;
  15. vector<string> a;
  16.  
  17. void vvod() {
  18.     cin >> good >> shablon >> n;
  19.     a.resize(n);
  20.     for (int i = 0; i < n; i++) {
  21.         cin >> a[i];
  22.     }
  23. }
  24.  
  25. void solve() {
  26.     vvod();
  27.     if (shablon.find('*') != string::npos) {
  28.         zv = true;
  29.     }
  30.     for (int i = 0; i < n; i++) {
  31.         int cur = 0;
  32.         no = false;
  33.         yes = false;
  34.         for (int j = 0; j < a[i].size(); j++) {
  35.             if (shablon[cur] >= 'a' && shablon[cur] <= 'z') {
  36.                 if (a[i][j] != shablon[cur]) {
  37.                     cout << "NO" << endl;
  38.                     no = true;
  39.                     break;
  40.                 }
  41.             }
  42.             if (shablon[cur] == '?') {
  43.                 if (good.find(a[i][j]) == string::npos) {
  44.                     cout << "NO" << endl;
  45.                     no = true;
  46.                     break;
  47.                 }
  48.             }
  49.             if (shablon[cur] == '*') {
  50.                 x = 0;
  51.                 while (a[i][j] != shablon[cur + 1] && j < a[i].size()) {
  52.                     if (good.find(a[i][j]) != string::npos) {
  53.                         cout << "NO" << endl;
  54.                         no = true;
  55.                         break;
  56.                     }
  57.                     j++;
  58.                     x++;
  59.                 }
  60.                 if (x == 0) {
  61.                     cur++;
  62.                     cout << "YES" << endl;
  63.                     yes = true;
  64.                     break;
  65.                 }
  66.                 j--;
  67.             }
  68.             cur++;
  69.         }
  70.         if (no) {
  71.             continue;
  72.         }
  73.         if (yes) {
  74.             continue;
  75.         }
  76.         if (cur < shablon.size()) {
  77.             if (zv && shablon.size() - cur == 1) {
  78.                 cout << "YES" << endl;
  79.                 continue;
  80.             }
  81.             cout << "NO" << endl;
  82.             continue;
  83.         }
  84.         cout << "YES" << endl;
  85.     }
  86. }
  87.  
  88. int main() {
  89.     ios_base::sync_with_stdio(false);
  90.     cin.tie(0);
  91.     cout.tie(0);
  92.     solve();
  93.     cout << endl;
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement