码迷,mamicode.com
首页 > 其他好文 > 详细

【考研】模式匹配

时间:2018-08-05 14:22:16      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:div   style   bst   pre   ret   substr   sub   font   lse   

①简单的模式匹配

int index(Str str,Str Substr)
{
    int i=1,j=1,k=i;
    while(i<=str.length&&j<=Substr.length)
    {
        if(str.ch[i]==Substr.ch[j])
        {
            i++;//i指向主串中的位置 
            j++;//j指向模式串中的位置 
        }
        else
        {
            j=1;
            i=++k;
        }
    }
    if(j>Substr.length) return k;//主串str.ch中的子串与模式串Substr.ch匹配后,j还是会+1,所以是j>Substr.length 
    else return 0;
} 

【考研】模式匹配

标签:div   style   bst   pre   ret   substr   sub   font   lse   

原文地址:https://www.cnblogs.com/kannyi/p/9425257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!