假设字符串str的长度为len,则str存在最小循环节,循环节的长度cycleLen为len-next[len],循环子串为str[0…len-next[len]-1]
- 如果len可以被len - next[len]整除,则表明字符串str可以完全由循环节循环组成
- 如果不能,说明还需要再添加几个字母才能补全,需要补的个数cycleLen-len%cycleLen,需要补充的字符串为str[len%cycleLen…cycleLen-len%cycleLen]
#include <iostream>
#include <vector>
using namespace std;
/* str 数组的 str.length() + 1 个next数组值 */
void getNext(string& str, vector<int>& next) {
next.at(1) = 0;
if (str.length() == 1)