首页 > 代码库 > 数据结构--模式匹配

数据结构--模式匹配

PART I:

#!/usr/bin/env python
#encoding=gbk
import sys
def BF():
    = "abbbbbbcdcdddcefg"
    = "bbbbcdcdddcef"
    = 0
    = 0
    print t, p, t.find(p)
    while i <= (len(t) - len(p)):
        """if t[i] == p[j]:move i and j to next"""
        """if t[i] != p[j]:reset i = i - j + 1 and reset j = 0"""
        if t[i + j] == p[j]:
            += 1
        else:
            += 1
            = 0
        if == len(p):
            return i
    return -1
 
if __name__ == "__main__":
    print BF()

数据结构--模式匹配