#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s1[100010],s2[50001];
int to[100010];
void getnext(char *a){
int i=-1,j=0,len=strlen(a);
to[0]=-1;
while(j<len){
if(i == -1 || a[i] == a[j])
{
to[++j]=++i;
}
else i=to[i];
}
return;
}
int main(){
while(scanf("%s", s1)!=EOF){
scanf("%s", s2);
int lena=strlen(s1),lenb=strlen(s2),len=lena+lenb;
strcat(s1,s2);
getnext(s1);
while(to[len]>lena || to[len]>lenb)
{
len=to[len];
//cout << len << endl;
}
len=to[len];
/*cout << len << endl;
for(int i = 0; i <= lena+lenb; i++){
cout << next[i] <<" ";
}
cout << endl;*/
for(int i=0;i<len;++i){
cout<<s1[i];
}
if(len){
cout<<' ';
}
cout<<len<<endl;
}
return 0;
}
KMP hdu2594
最新推荐文章于 2019-09-27 20:36:43 发布