#include<iostream>
using namespace std;
void GetNext(string &str, int next[]){
next[0] = -1;
int i = 0, j = -1;
while (i < str.size()-1){
if (j == -1 || str[i] == str[j]){
++i;
++j;
next[i] = j;
}
else{
j = next[j];
}
}
}
int main()
{
string str;
int next[100];
cin >> str;
GetNext(str, next);
for(int i=0;i<str.size();i++){
cout<<next[i]<<" ";
}
return 0;
}
求给定一个串的next值(next[0]=-1)
最新推荐文章于 2023-08-03 17:35:08 发布