#Boyer-Moore string searchdefcontain_char(s,c):
i =0for _ in s[::-1]:if c == _:returnlen(s)-1-i
i+=1returnFalsedefcom_str(str1,str2):if str1 == str2:returnTrueelse:returnFalsedefbms(pa,txts,start=0):
len_p =len(pa)
tmp =[]
i = len_p-1while i <len(txts)and i >-1:print(i)if pa[-1]!= txts[i]:
t = contain_char(pa,txts[len_p-1])if t ==False:
i += len_p
else:
i += t
else:if pa[:-1]== txts[i+1-len_p:i]:
tmp.append(i+1-len_p)
i+=len_p
continueelse:
i+=len_p
continuereturn tmp
#测试
t1 = bms('ch','aechwww')print(t1)