L1-058 6翻了 python
python 实现
注:测试的时候最后一个测试点总是不通过,最后发现,测试数据可能是一个不含空格的长单词,单词内同样包含6,如:
输入:
zhangsan666-lisi666666-wangwu6666666666
输出:
zhangsan666-lisi9-wangwu27
s=input() t="" i=0 while True: count = 0 if s[i]=="6": for j in range(i,len(s)): if s[j]=="6": count+=1 else: break if count > 9: t = t+"27" elif count >3: t = t+"9" else: t = t + s[i]*count i=i+count else: t = t + s[i] i += 1 if i == len(s): break print(t)