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<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<LEN1&&J<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<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)