Give a string SS and NN string T_iTi , determine whether T_iTi is a subsequence of SS.
If ti is subsequence of SS, print YES
,else print NO
.
If there is an array \lbrace K_1, K_2, K_3,\cdots, K_m \rbrace{K1,K2,K3,⋯,Km}so that 1 \le K_1 < K_2 < K_3 < \cdots < K_m \le N1≤K1<K2<K3<⋯<Km≤N and S_{k_i} = T_iSki=Ti, (1 \le i \le m)(1≤i≤m), then T_iTi is a subsequence of SS.
Input
The first line is one string SS,length(SS) \le 100000≤100000
The second line is one positive integer N,N \le 100000N,N≤100000
Then next nn lines,every line is a string T_iTi, length(T_iTi) \le 1000≤1000
Output
Print NN lines. If the ii-th T_iTi is subsequence of SS, print YES
, else print NO
.
样例输入复制
abcdefg 3 abc adg cba
样例输出复制
YES YES NO
直接暴力模拟就行了,遍历 串的每个字符,在 串中寻找有没有,如果没有的话就返回 false.
代码:
#include<set>
#include<map>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char s[100005];
char t[10004];
int main()
{
int n;
scanf("%s",s);
scanf("%d",&n);
while(n--)
{
scanf("%s",t);
int len=strlen(t);
int zlen=strlen(s);
int j=len-1;
int flog=0;
if(zlen<len)
{
printf("NO\n");
continue;
}
else
{
for(int i=zlen-1; i>=0; i--)
{
if(t[j]==s[i])
{
//printf("%d %d\n",i,j);
//printf("%c %c\n",t[j],s[i]);
j--;
flog++;
}
if(j<0)
break;
}
}
if(flog==len)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}