• hdu 2203亲和串 (kmp)


    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<string>
    using namespace std;
    int Next[100005];
    void getnext(const char *W,int *next)
    {
        int j=0,k=-1;
        next[0]=-1;
        while(!j || W[j]!='')
        {
            if(k==-1 || W[j]==W[k])
            {
                j++;
                k++;
                if(W[j]!=W[k])
                    next[j]=k;
                else
                    next[j]=next[k];
            }
            else k=next[k];
        }
    }
    int KMP(const char *T,const char *W)
    {
        int i=0,j=0,num=0;
        getnext(W,Next);
        int tlen,wlen;
        tlen=strlen(T);
        wlen=strlen(W);
        while(i<tlen)
        {
            if(j==-1 || T[i]==W[j])
            {
                i++;
                j++;
            }
            else
            {
                j=Next[j];
            }
            if(j==wlen)
            {
                return 1;
            }
        }
        return 0;
    }
    char str[200005],str1[100005],str2[100005];
    int main()
    {
        int n;
        while(cin>>str1>>str2)
        {
            int len=strlen(str1);
            int len1=strlen(str2);
            if(len1>len) {cout<<"no"<<endl;
            continue;
            }
            strcpy(str,str1);
            strcpy(&str[len],str1);
            if(KMP(str,str2)) cout<<"yes"<<endl;
            else  cout<<"no"<<endl;
        }
        return 0;
    }

  • 相关阅读:
    Twitter注册
    iOS项目的完整重命名方法图文教程
    加载gif动态图的三种方式
    只 一行显示可左右滚动的文本(UITextField中文限制)
    iOS学习资料链接
    GCD常用方法
    移动端轮播完整版css3加原生写法
    zepto-touch.js插件
    移动端续讲及zepto移动端插件外加touch插件介绍
    解决ios和Android的差异
  • 原文地址:https://www.cnblogs.com/woshijishu3/p/4100366.html
Copyright © 2020-2023  润新知