#include <iostream>
#include<cstring>
using namespace std;
int BF(string S,string T)
{
int i=0;
int j=0;
while(S[i]!='\0' && T[i]!='\0')
{
if(S[i]==T[j])
{
i++;
j++;
}
else
{
i=i-j+1;
j=0;
}
}
if(T[i]=='\0')
return (i-j+1);
else
return 0;
}
int main()
{
string S,T;
cout<<"cin:S"<<endl;
cin>>S;
cout<<"cin:T"<<endl;
cin>>T;
cout<<BF(S,T)<<endl;
return 0;
}
BF算法
最新推荐文章于 2022-10-29 17:24:41 发布
本文介绍了一个 Boyer-Moore 字符串匹配算法的具体实现,该算法通过预处理模式串来提高搜索效率。代码示例使用 C++ 编写,并通过标准输入接收目标字符串和模式串。
1586

被折叠的 条评论
为什么被折叠?



