zoukankan      html  css  js  c++  java
  • 一种比KMP更优的字符串模式匹配算法

    源码如下:
    /**=========================================================
    * 版权:****************************
    * 文件: .SundaySUANFAN.java
    * 所含类: SundaySUANFAN.java
    * 修改记录:
    * 日期                  作者           内容
    * =========================================================
    * 2010-4-22          李星星         创建文件,实现基本功能
    */

    public class SundaySUANFAN {

    public static int sunday(String resoure,String destination){
    int i,j,pos=0; 
    int len_s,len_d; 
    int next[]=new int[26];                             
    len_s=resoure.length(); 
    len_d=destination.length(); 
    for(j=0;j<26;++j)                      
    next[j]=len_d; 
    for(j=0;j<len_d;++j)                      
    next[destination.charAt(j)-'a']=len_d-j;  
    while( pos<(len_s-len_d+1) )              

    i=pos; 
    for(j=0;j<len_d;++j,++i)            

    if(resoure.charAt(i)!=destination.charAt(j))             

    pos+=next[resoure.charAt(pos+len_d)-'a']; 
    break; 


    if(j==len_d) 
    return pos; 

    return -1;      
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    String src = "abcdbbcdceedacdaahfacabcdabcdeaa";
    String des = "bcde";

    System.out.println(sunday(src, des));
    }

    }
  • 相关阅读:
    使用js获取表单元素的值
    分页问题
    空值转换问题
    MySQL数据库操作基础
    二叉树DFS遍历递归和非递归做法
    BFS经典算法
    stack & queue及经典例题
    Recursion & Binary search
    Leetcode之SpiralMatrix(I,II)
    Leetcode之贪心算法
  • 原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100636.html
Copyright © 2011-2022 走看看