滑动窗口
import sys
x, y = input().split()
lik_lis = input().split()
like = set()
for i in lik_lis:
like.add(i)
instr = list(input())#变成可编辑的list
add_list = []
for n in range(len(instr)):#划分窗口
if instr[n] in like:
add_list.append(n)
add_list.append(int(x*3))#屎山,用来处理越界
pl = add_list[0]
ph = add_list[1]
psl = 0
psh = 1
for n in range(len(instr)):
if pl <= n <= ph:#如果在窗口里
delx = n - pl#计算距离
dely = ph - n
if delx > dely:
instr[n] = instr[ph]
else:
instr[n] = instr[pl]
elif n < pl:#在窗口左面
instr[n] = instr[pl]
elif n > ph:#在窗口右面
psl += 1#更新窗口
psh += 1
pl = add_list[psl]
ph = add_list[psh]
delx = n - pl#在中间的处理方式
dely = ph - n
if delx > dely:
instr[n] = instr[ph]
else:
instr[n] = instr[pl]
print(''.join(instr))

京公网安备 11010502036488号