BF串匹配算法

#include
int BF(char *s,char *t){
int index = 0, i = 0, j = 0;
while ((s[i] != '\0') && (t[j] != '\0'))
	{
		if (s[i] == t[j]){ i++; j++; }
		else { index++; i = index; j = 0;}//子串从零开始,主串从0+1步开始
	}

	if (t[j] == '\0') return index + 1;
	else return 0;
	return 0;
}
int main(){

	char s[] = "ababc";
	char t[] = "abc";
	printf("%d", BF(s, t));
	return 0;
}

你可能感兴趣的:(数据结构,算法)