64,654
社区成员
发帖
与我相关
我的任务
分享
void GetNext(const char *Str,int *next)
{
int j=0, k=-1;
int len = strlen(Str);
next[0] = -1;
int temp = 0 ;
while(j < len)
{
if (k==-1 || Str[j] == Str[k])
{
j++;
k++;
printf( "j =%d,k = %d\r\n", j ,k ) ;
next[j] = k;
}
else
{
printf( "k = %d\r\n" , k ) ;
k = next[k];
}
}
int b = 0 ;
}
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;
void GetNext(const char *Str,int *next)
{
int j=0, k=-1;
int len = strlen(Str);
next[0] = -1;
while(j < len)
{
if (k==-1 || Str[j] == Str[k])
{
j++;
k++;
next[j] = k;
}
else
k = next[k];
}
}
int main()
{
char *q = "abcaa";
int next[6] ={0};
GetNext(q,next);
printf( "%s", q) ;
getchar() ;
return 0 ;
}
char q[] = "abcaa";