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

样例输出复制

YES
YES
NO

给一个字符串s1,查看n个字符串s2的字母是否顺序出现在字符串s1中是则输出YES不是则输出NO

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

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s1[100000];
char s2[100000];
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;
}

 

©️2020 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值