标签:
#include<stdio.h> #include<string.h> const int MAXN = 1e5+7; const int oo = 1e9+7; char a[MAXN], b[MAXN]; int next[MAXN]; void GetNext(char s[], int N) { int i=0, j=-1; next[0] = -1; while(i < N) { if(j==-1 || s[i]==s[j]) next[++i] = ++j; else j = next[j]; } } int main() { while(scanf("%s%s", a, b) != EOF) { int N = strlen(a); a[N] = ‘*‘, a[N+1] = 0; strcat(a, b); N = strlen(a); GetNext(a, N); if(next[N] == 0) printf("0\n"); else { a[next[N]] = 0; printf("%s %d\n", a, next[N]); } } return 0; }
Simpsons’ Hidden Talents - HDU 2594(求相同的前缀后缀)
标签:
原文地址:http://www.cnblogs.com/liuxin13/p/4731847.html