Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************
- ** Solution by daun **
- ***********************/
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e5 + 5;
- const int INF = 4127;
- const int mod = 475;
- string good, shablon;
- int n, x = -1;
- bool no = false, zv = false, yes = false;
- vector<string> a;
- void vvod() {
- cin >> good >> shablon >> n;
- a.resize(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- }
- void solve() {
- vvod();
- if (shablon.find('*') != string::npos) {
- zv = true;
- }
- for (int i = 0; i < n; i++) {
- int cur = 0;
- no = false;
- yes = false;
- for (int j = 0; j < a[i].size(); j++) {
- if (shablon[cur] >= 'a' && shablon[cur] <= 'z') {
- if (a[i][j] != shablon[cur]) {
- cout << "NO" << endl;
- no = true;
- break;
- }
- }
- if (shablon[cur] == '?') {
- if (good.find(a[i][j]) == string::npos) {
- cout << "NO" << endl;
- no = true;
- break;
- }
- }
- if (shablon[cur] == '*') {
- x = 0;
- while (a[i][j] != shablon[cur + 1] && j < a[i].size()) {
- if (good.find(a[i][j]) != string::npos) {
- cout << "NO" << endl;
- no = true;
- break;
- }
- j++;
- x++;
- }
- if (x == 0) {
- cur++;
- cout << "YES" << endl;
- yes = true;
- break;
- }
- j--;
- }
- cur++;
- }
- if (no) {
- continue;
- }
- if (yes) {
- continue;
- }
- if (cur < shablon.size()) {
- if (zv && shablon.size() - cur == 1) {
- cout << "YES" << endl;
- continue;
- }
- cout << "NO" << endl;
- continue;
- }
- cout << "YES" << endl;
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- solve();
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement