Solution
##Code
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int DEG = 20;
const double PI = acos(-1.0);
const double eps = 1e-10;
const ll inf = 1e18;
static auto faster_iostream = []() {
std::ios::sync_with_stdio(false); // turn off sync
std::cin.tie(nullptr); // untie in/out streams
return 0;
}();
int nextz[N][26];
int tmp[30];
string s;
bool solve(string t){
int cur = 0; // 主串位置
int id = 0; // 模式串位置
while(id < t.size()){
if(cur >= s.size()){ // 主串已经匹配完,模式串还没到结尾
return false;
}
if(s[cur] == t[id]){ // 当前位相同,直接匹配
id++;
cur++;
continue;
}
if(nextz[cur][t[id] - 'a'] == -1){ // 下一个该字母不存在
return false;
}
cur = nextz[cur][t[id] - 'a'] + 1; // 到下一个该字母的下一位
id++;
}
return id == t.size();
}
int main(){
cin >> s;
memset(tmp, -1, sizeof(tmp));
for(int i = s.size() - 1; i >= 0; i--){
for(int j = 0; j < 26; j++){
nextz[i][j] = tmp[j];
}
tmp[s[i] - 'a'] = i;
}
int n;
cin >> n;
for(int i = 1; i <= n; i++){
string t;
cin >> t;
if(solve(t)){
cout << "Yes\n";
}
else cout << "No\n";
}
return 0;
} 
京公网安备 11010502036488号