# 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 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
cba

YES
YES
NO

写起来很简单直接上代码：

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s1;
char s2;
int main()
{
scanf("%s",s1);
int len1 = strlen(s1);
int t;
cin>>t;
int flag;
while(t--){
memset(s2,0,sizeof(s2));
scanf("%s",s2);
int b = 0;
int len2 = strlen(s2);
for(int i = 0;i<len2;i++){
flag = 0;
for(int j = b;j<len1;j++){
if(s2[i] == s1[j]){
flag = 1;
b = j + 1;
break;
}
}
if(flag == 0){
printf("NO\n");
break;
}
}
if(flag == 1)
printf("YES\n");
}
return 0;
}

10-07 1984

#### MOOC ：01-复杂度2 Maximum Subsequence Sum

08-14 2014

#### subsequence和substring的区别 12-08 408

#### Palindrome subsequence

02-21 175

#### CodeForces Gym 101741 J. Subsequence Sum Queries

02-18 117

#### 求助！【PAT】01-复杂度2 Maximum Subsequence Sum （25 分）一个测试点怎么也过不去！

10-12

04-29 384

#### subsequence ©️2020 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客 点击重新获取   扫码支付 1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。 余额充值