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)