Problem Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know th…
题解:对于串pattern来说,如果0~i-1这个位置中循环,那么i%(i-next[i])==0 ,循环次数为 i/(i-next[i]),循环长度为 i-next[i] 例如对于串ababab来说 index 0 1 2 3 4 5 char a b a b a b next -1 0 0 1 2 1 对于index=4时,i%(i-next[i])==0,而0~3位置的字符存循环. 代码: #include<cstdio> #include<iostream> #…
链接: https://vjudge.net/problem/HDU-1358#author=0 题意: For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i…