题目如下 :
题解代码如下:
n = int(input())
p = input()
m = int(input())
s = input()
def get_next(p):
l = len(p)
next_ = [-1]
i = 0
j = -1
while i < l:
if j == -1 or p[i] == p[j]:
i += 1
j += 1
next_.append(j)
else:
j = next_[j]
return next_
next_ = get_next(p)
i = 0
j = 0
while i < m:
if j == -1 or p[j] == s[i]:
i += 1
j += 1
else:
j = next_[j]
if j == n:
print(i - n,end = " ")
j = next_[j]