HDU 2203 Affinity String (to two string s1,s2, ask S2 can not appear in the string with S1 as the Loop section)

Source: Internet
Author: User

1.strcat function, strcat (char *s, char *p); Note that the memory area of S and p here cannot overlap and s must have enough space to hold the string of P

2.strcpy function, strcpy (char *s,char *p), copy p to s

3. Code:

#include <cstdio> #include <cstring>using namespace Std;char s1[1000000],s2[100005],t[1000000];int len1,    Len2;//int lcps[100005];int next[100005];void Getlcps () {int j=0;    int k=-1;    Next[0]=-1; while (J&LT;LEN2) {if (k==-1| |            S2[k]==s2[j]) {//lcps[j++]=++k;            j + +;            ++k;        Next[j]=k;            } else {//if (k-1>=0) k=next[k];        else//k=-1;    }}}void KMP () {int i=0;    int j=0; while (I&LT;LEN1&AMP;&AMP;J&LT;LEN2) {if (j==-1| |            S1[i]==s2[j]) {j + +;        i++;    } else j=next[j];    } if (j==len2) printf ("yes\n"); else printf ("no\n");}        int main () {while (scanf ("%s%s", S1,s2) ==2) {Len1=strlen (S1);        Len2=strlen (S2);            while (LEN1&LT;LEN2) {strcpy (T,S1);            strcat (s1,t);        Len1=strlen (S1); } strcpy (T,s1);        strcat (s1,t);        Len1=strlen (S1);        Getlcps ();    KMP (); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 2203 Affinity String (to two string s1,s2, ask S2 can not appear in the string with S1 as the Loop section)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.