求各位大佬看一下,谢谢大佬们!
s1=input()
s2=input()
def nextArr(son):
next = [-1] * len(son)
if len(son) > 1:
next[1] = 0
i, j = 0, -1
while i < len(son) - 1:
if j == -1 or son[i] == son[j]:
i += 1
j += 1
next[i] = j
else:
j = next[j]
return next
def kmp(mom,son):
test=''
if type(mom)!=type(test) or type(son)!=type(test):
return -1
if len(son)==0:
return 0
if len(mom)==0:
return -1
m=s=0
next=nextArr(son)
while m<len(mom):
if s==-1 or mom[m]==son[s]:
m+=1
s+=1
else:
s=next[s]
if s == len(son):
print(m - s + 1)
m=m-s+1
s=0
return -1
kmp(s1,s2)
border=nextArr(s2+' ')
s=str(border[1])+' '
for x in border[2::]:
s+=str(x)+' '
print(s)