#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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.