Period POJ - 1961(KMP找最小循环节)

题目

给你字符串A,问你A串的所有的前缀子串中,有循环节的子串输出最小循环节

思路

典型的KMP找最小循环,只要遍历所有的前缀子串,找出所有前缀子串的最小循环节就可以。最小循环接周期T=字符串长度-next[len] 如果字符串长度%T==0说明存在最小循环节输出

#include 
#include 
#include 

using namespace std;

const int MAXN=1e6+10;
char str1[MAXN],str2[MAXN];
int snext[MAXN];
int len;


void getnext()
{
    len=strlen(str1);
    int j=0;
    int k=snext[0]=-1;
    while(j>T&&T)
    {   
        scanf("%s",str1);
        printf("Test case #%d\n",kcae++);
        getnext();
        for(int i=1;i

 

你可能感兴趣的:(字符串/KMP)