标签:
Description
Input
Output
Sample Input
bcabcab efgabcdefgabcde
Sample Output
3 7
#include <stdio.h> #include <string.h> using namespace std; const int maxn=1000010; char t[maxn]; int n[maxn]; int len; void get_next() { int i=0; int j=-1; n[0]=-1; while(i<len) { if(j==-1||t[i]==t[j]) { i++; j++; n[i]=j; } else j=n[j]; } } int main() { while(scanf("%s",t)!=EOF) { int j,i; len=strlen(t); memset(n,0,sizeof(n)); get_next(); printf("%d\n",len-n[len]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/tianmin123/p/4666863.html