A - KMP模式匹配 一(串)
Crawling in process...
Crawling failed
Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu
Description
求子串的next值,用next数组存放,全部输出
Input
输入一个字符串
Output
输出所有next值
Sample Input
abaabcac
Sample Output
0 1 1 2 2 3 1 2
Hint
#include <iostream>
#include<cstdio>
#include<string.h>
using namespace std;
const int maxn=100001;
int len;
void getnext(char s[maxn],int next[maxn])
{
len=strlen(s);
int i=0,j=-1;
next[0]=-1;
while(i<len)
{
if(j==-1||s[i]==s[j])
{
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
}
int main()
{
char a[maxn];
int next[maxn];
int i;
cin>>a;
len=strlen(a);
getnext(a,next);
for(i=0; i<len-1; i++)
printf("%d ",next[i]+1);
printf("%d",next[i]+1);
return 0;
}