KMP字符串匹配

#include
using namespace std;

void Get_Next(char* T,int* next);      
void Get_Nextval(char* T,int* next);   
int Index_KMP(char* S,char* T,int* N); 

int main()
{
char S[500];
char T[255];
    int N[255];

cout<
cin>>S;
cout<
cin>>T;

Get_Next(T,N);
// Get_Nextval(T,N);
for(int i=0;i
{
cout<
}
cout<

//cout<

    return 0;
}


int Index_KMP(char* S,char* T,int* N)
{
int i,j;
i=0;
j=0;
int sl = strlen(S);
int tl = strlen(T);
while(i
{
if(j == -1 ||S[i] == T[j])
{
i++;
j++;
}
else
{
j = N[j];
}
}
if(j==strlen(T))
{
return i-j;
}
else
{
return -1;
}
    
}


void Get_Next(char* T,int* next)
{
int i,j;
i=0;
j=-1;
next[0]=-1;
while(i
{
if(j==-1 || T[i] == T[j])
{
i++;
j++;
next[i] = j;
}
else
{
j = next[j];
}
}
}


void Get_Nextval(char* T,int* next)
{
int i,j;
i=0;
j=-1;
next[0]=-1;
while(i
{
if(j==-1 || T[i] == T[j])
{
i++;
j++;
if (T[i] != T[j])
   next[i] = j;
else
                next[i] = next[j];
}
else
{
j = next[j];
}
}
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25361369/viewspace-720121/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 冒泡排序
下一篇: 二叉树遍历
user_pic_default.png
请登录后发表评论 登录
全部评论
<%=items[i].createtime%>

<%=items[i].content%>

<%if(items[i].items.items.length) { %>
<%for(var j=0;j
<%=items[i].items.items[j].createtime%> 回复

<%=items[i].items.items[j].username%>   回复   <%=items[i].items.items[j].tousername%><%=items[i].items.items[j].content%>

<%}%> <%if(items[i].items.total > 5) { %>
还有<%=items[i].items.total-5%>条评论 ) data-count=1 data-flag=true>点击查看
<%}%>
<%}%>
<%}%>

转载于:http://blog.itpub.net/25361369/viewspace-720121/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值