M. Subsequence(问一个字符串是否是另一个串的子序列)

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 printNO.

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​

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

check[i][j]数组预处理一下,当前i位置的下一个j字母在哪个位置

队友做的,偷偷贴代码

#include 

using namespace std;

#define ll long long
#define debug printf("PASS IN LINE:%d\n",__LINE__)
#define reg register
int input(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

#define N (int)(1e5+7)

char s[N];
int check[N][26];

int main(){
	scanf("%s",s);
	int len=strlen(s);
	for(reg int i=0;i<26;++i) check[len-1][i]=-1;
	
	for(reg int i=len-2;i>=0;--i){
		for(reg int j=0;j<26;++j){
			if(j==s[i+1]-'a') check[i][j]=i+1;
			else check[i][j]=check[i+1][j];
		}
	}

	 /*for(int i=0;i

 

你可能感兴趣的:(M. Subsequence(问一个字符串是否是另一个串的子序列))