题目链接:
事实上就是KMP算法next数组的简单应用。假设我们设这个字符串的最小周期为x 长度为len,那么由next数组的意义,我们知道len-next[len]的值就会等于x。这就是这个题目的关键点。代码例如以下:
#include#include #include using namespace std;const int maxn=1000000+100;char str[maxn];int next[maxn];int kmp_next(char x[],int m,int next[]){ int i,j; j=next[0]=-1; i=0; while(i