zoukankan      html  css  js  c++  java
  • Subsequence (暴力搜索)

    Give a string SSS and NNN string TiT_iTi , determine whether TiT_iTi is a subsequence of SSS.

    If ti is subsequence of SSS, print YES,else print NO.

    If there is an array {K1,K2,K3,⋯ ,Km}lbrace K_1, K_2, K_3,cdots, K_m brace{K1,K2,K3,,Km} so that 1≤K1<K2<K3<⋯<Km≤N1 le K_1 < K_2 < K_3 < cdots < K_m le N1K1<K2<K3<<KmN and Ski=TiS_{k_i} = T_iSki=Ti, (1≤i≤m)(1 le i le m)(1im), then TiT_iTi is a subsequence of SSS.

    Input

    The first line is one string SSS,length(SSS) ≤100000 le 100000100000

    The second line is one positive integer N,N≤100000N,N le 100000N,N100000

    Then next nnn lines,every line is a string TiT_iTi, length(TiT_iTi) ≤1000le 10001000

    Output

    Print NNN lines. If the iii-th TiT_iTi is subsequence of SSS, print YES, else print NO.

    样例输入 

    abcdefg
    3
    abc
    adg
    cba

    样例输出 

    YES
    YES
    NO
    #include <cstdio>
    #include <iostream>
    #include <vector>
    #include <string>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    using namespace std;
    #define ll long long
    const int inf = 0x3f3f3f3f;
    const  ll linf  =1LL<<50;
    const int maxn = 1e5+8;
    string s, miao;
    int n;
    int main()
    {
        cin>>s;
        int l = s.size();
        cin >> n;
        while(n--)
        {
            cin>>miao;
            int len = miao.size();
            int ga = 0;
            for(int i = 0; i<l; i++)
            {
                if(miao[ga] == s[i])
                {
                    ga++;
                }
                if(ga == len)break;
            }
            if(ga == len)printf("YES
    ");
            else printf("NO
    ");
        }
        return 0;
    }
  • 相关阅读:
    win10远程桌面连接提示身份验证错误,要求的函数不受支持的解决方案
    十六进制转八进制
    十六进制转十进制
    十进制转十六进制
    LEETCODE
    LINUX
    LINUX
    LEETCODE
    LEETCODE
    LEETCODE
  • 原文地址:https://www.cnblogs.com/RootVount/p/10752507.html
Copyright © 2011-2022 走看看