#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef char SString[1000];
int next[1000];
int nextval[1000];
void get_next(SString T, int next[])
{
int i = 1, j = 0;
next[1] = 0;
while (i < T[0])
{
if (j == 0 || T[i] == T[j])
{
++i;
++j;
next[i] = j;
}
else
j = next[j];
}
}
void get_nextval(SString T, int nextval[])
{
int i = 1, j = 0;
nextval[1] = 0;
while (i < T[0])
{
if (j == 0 || T[i] == T[j])
{
++i;
++j;
if (T[i] != T[j])
nextval[i] = j;
else
nextval[i] = nextval[j];
}
else
j = nextval[j];
}
}
int main()
{
SString S,T;
gets(T);
// gets(S);
T[0]=strlen(T);
S[0]=strlen(S);
get_next(T,next);
get_nextval(T,nextval);
int i,j;
for(i=1;i<=T[0];i++)
printf("%3d",next[i]);
// for(j=1;j<=T[0];j++)
// printf("%3d",nextval[j]);
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/236284.html
標籤:C++ 語言
