The question is to find the prefix of the first character and the Public sequence with the largest Suffix of the last string, and output it...
Combine the two strings and find the next array in KMP. However, be sure not to exceed the length of a string;
# Include <stdio. h>
# Include <string. h>
Const int n= 50005;
# Define min (A, B) (a) <(B )? (A) (B ))
Char S1 [N], S2 [N], S3 [N * 2];
Int next [N * 2];
Void get_next (char * seq, int m ){
Next [0] =-1;
Int J = next [0];
For (INT I = 1; I <m; I ++ ){
While (j> = 0 & seq [I]! = Seq [J + 1]) J = next [J];
If (SEQ [I] = seq [J + 1]) J ++;
Next [I] = J;
}
}
Int main (){
While (~ Scanf ("% S % s", S1, S2 )){
Int len1 = strlen (S1), len2 = strlen (S2 );
Strcpy (S3, S1); strcpy (S3 + len1, S2 );
Int len3 = strlen (S3 );
Get_next (S3, len3 );
Int ans = min (len1, len2), next [len3-1] + 1 );
For (INT I = 0; I <ans; I ++)
Printf ("% C", S1 [I]);
Printf ("% d \ n", ANS );
If (ANS) printf ("");
Printf ("% d \ n", ANS );
}
Return 0;
}