You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
char str1[N], str2[N];
//vector<int> v[256];
int v[256][N];
int cnt[256];
int main()
{
//printf("Time: %lf\n", chrono::system_clock::now().time_since_epoch().count() / 1e7);
//freopen("D:\\1.txt", "r", stdin);
int n;
scanf("%s%d", str1, &n);
//int len1 = strlen(str1);
char *p = str1;
for (int i = 0; *p; i++, p++)
//v[str1[i]].push_back(i);
v[*p][cnt[*p]++] = i;
//printf("Time: %lf\n", chrono::system_clock::now().time_since_epoch().count() / 1e7);
while (n--)
{
scanf("%s", str2);
p = str2;
int id = -1;
bool flag = true;
for (int i = 0; *p && flag; i++, p++)
{
auto V = v[*p];
auto ite = upper_bound(V, V + cnt[*p], id);
if (ite == V + cnt[*p])
flag = false;
else
id = *ite;
}
puts(flag ? "YES" : "NO");
}
//printf("Time: %lf\n", chrono::system_clock::now().time_since_epoch().count() / 1e7);
return 0;
}