描述
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。
输入
输入包括多行。
每行是一个字符串,长度不超过200。
一行的末尾与下一行的开头没有关系。
输出包含多行,为输入按照描述中变换的结果。
样例输入
The Marshtomp has seen it all before.
marshTomp is beaten by fjxmlhx!
AmarshtompB
样例输出
The fjxmlhx has seen it all before.
fjxmlhx is beaten by fjxmlhx!
AfjxmlhxB
AC的python代码
while True:
try:
t = input()
lss = t.lower()
tss = t
c = list()
if "marshtomp" not in lss: #no need to process the string
print(tss)
continue
if "marshtomp" in lss:
ind = lss.index("marshtomp")
ct = tss[ind : ind + 9]
lss = lss[ind + 9:] #to avoid the repeated search
c.append(ct) # a list used to store the "marshtomp" in different case
indtep = ind # record the start index
while( "marshtomp" in lss):
ind = lss.index("marshtomp")
lss = lss[ind + 9:]
ind = ind + indtep + 9
ct = tss[ind : ind + 9]
indtep = ind
c.append(ct)
for st in c:
tss = tss.replace(st, "fjxmlhx")
print(tss)
except EOFError:
break
注意事项
- 多输入的格式
while True:
try:
except EOFError:
break
- str.replace()会将所有的old str替换为new str,所以不可用于lss。
tss = tss.replace(st, "fjxmlhx")
- 中间那么长一段是为了将不同case的marshtomp读出,目前只完成了AC,可能有较大改进空间,有思路以后可能会进行更新。