1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; int nxt[maxn][26];
char s[maxn], t[maxn];
int main() { scanf("%s", s + 1); int len = strlen(s + 1); for (int i = len; i >= 1; i--) { for (int j = 0; j < 26; j++) { nxt[i - 1][j] = nxt[i][j]; } nxt[i - 1][s[i] - 'a'] = i; }
int q; scanf("%d", &q); while(q--) { scanf("%s", t); int len1 = strlen(t); int f = 0; for (int i = 0, u = 0; i < len1; i++) { int v = t[i] - 'a'; u = nxt[u][v]; if(u==0) { f = 1; break; } } if(f) { printf("NO\n"); } else printf("YES\n"); } }
|