PART I:
#!/usr/bin/env python
#encoding=gbk
import
sys
def
BF():
t
=
"abbbbbbcdcdddcefg"
p
=
"bbbbcdcdddcef"
i
=
0
j
=
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]:
j
+
=
1
else
:
i
+
=
1
j
=
0
if
j
=
=
len
(p):
return
i
return
-
1
if
__name__
=
=
"__main__"
:
print
BF()
时间: 2024-10-21 01:51:02