热门

最新

红包

立Flag

投票

同城

我的

发布
qq_52111887
头是toto的
4 年前
trueqq_52111887

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char sub[100],str[100];
int i=0,j=-1;
int Next[100];
Next[0]=-1;
gets(str);
gets(sub);
while(sub[i]!=0)
{
if(j==-1||sub[i]==sub[j])
{
i++;
j++;
Next[i]=j;
}
else
{
j=Next[j];
}
}
i=0;
j=0;
while(i<strlen(str)&&j<strlen(sub))
{
if(str[i]==sub[j]||(j==-1))
{
i++;
j++;
}
else
{
j=Next[j];
}
}
if(j==strlen(sub))
cout<<"子串在母串中的位置是"<<i-strlen(sub);
else
cout<<"无";
return 0;
}
有没有好心人帮我看看这个kmp代码为什么不对

你问我答
CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
CSS知识点集合https://blog.csdn.net/xliang111/article/details/115838262
立即登录