bf演算法c語言
發布時間: 2022-06-10 02:14:10
int Index(SString S,SString T,int pos)
{ /* 返回子串T在主串S中第pos個字元之後的位置。若不存在,則函數值為0。 */
/* 其中,T非空,1≤pos≤StrLength(S)。演算法4.5 */
int i,j;
if(1<=pos&&pos<=S[0])
{
i=pos;
j=1;
while(i<=S[0]&&j<=T[0])/*S[0],T[0]中存放的為串長*/
if(S[i]==T[j]) /* 繼續比較後繼字元 */
{
++i;
++j;
}
else /* 指針後退重新開始匹配 */
{
i=i-j+2;
j=1;
}
if(j>T[0])
return i-T[0];
else
return 0;
}
else
return 0;
}
2. 一個簡單的小程序 C語言 BF演算法
引用沒問題,就是BF函數錯了。
#include<stdio.h>
#include<string.h>
#include<iostream>//.h去掉
usingnamespacestd;//命名空間
intBF(charS[],charT[])
{
inti,j,start;
i=0;
j=0;
start=0;
while(S[i]!='