Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2594
Idea: Concatenate two to find the next array is the sum of the two, the length of the traverse should be less than the minimum value of two strings
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <math.h>5#include <string.h>6#include <vector>7#include <queue>8#include <iterator>9#include <vector>Ten#include <Set> One #defineDinf 0x3f3f3f3f AtypedefLong Longll; - //const int max= (1<<16) +10; - using namespacestd; the - Const intmax=50000+Ten; - Chars1[max*2],s2[max]; - intnext[max*2]; + - voidGet_next (Char*a) { + inti=-1, j=0, len=strlen (a); Anext[0]=-1; at while(j<Len) { - if(i = =-1|| A[i] = = A[j]) next[++j]=++i; - ElseI=Next[i]; - } - return; - } in - intMain () { to while(cin>>s1>>S2) { + intLena=strlen (S1), Lenb=strlen (S2), len=lena+LenB; - strcat (S1,S2); the Get_next (S1); * while(Next[len]>lena | | NEXT[LEN]>LENB) len=Next[len]; $len=Next[len]; Panax Notoginseng for(intI=0; i<len;++i) cout<<S1[i]; - if(len) cout<<' '; thecout<<len<<Endl; + } A return 0; the}
Hdu 2594 Simpsons ' Hidden talents