コード例 #1
0
ファイル: main.cpp プロジェクト: fzls/AllTheSourceCodes
int main(){
	int *s;
	int *t;
	int *v;
	int *next;
	int MaxLenthOf_S =MAXSIZE;
	int MaxLenthOf_t=MAXSIZE;
	int MaxLenthOf_v=MAXSIZE;
	s=(int *)malloc((MAXSIZE+1)*sizeof(int));
	t=(int *)malloc((MAXSIZE+1)*sizeof(int));
	v=(int *)malloc((MAXSIZE+1)*sizeof(int));
	next=(int *)malloc((MAXSIZE+1)*sizeof(int));
	if(!s||!t||!v||!next)
		return OVERFLOW;
	int i;
	printf("please input three strings  respectively and don't forget to split them with the enter\n");
	input(s,MaxLenthOf_S);
	input(t,MaxLenthOf_t);
	input(v,MaxLenthOf_v);
	MakeNext(s,next);
	replace(s,t,v,next);
	for (i = 1; i <= s[0]; ++i)
	{
		printf("%c", s[i]);
	}
	printf("\n");
}
コード例 #2
0
int KMP(int* T,int N,int* P,int M)
{
    MakeNext(P,M,Next);
    int i=0,j=0;
    while(i<N&&j<M){
        if(T[i]==P[j]||j==-1)i++,j++;
        else j = Next[j];
    }
    if(j==M)return i-M;
    else return -2;
}