對于多個重復字符的字串,我的代碼作業正常,但這里的情況是,我給出字串 "aaabba",預期輸出是a3b2a1,但我只得到a3b2。請告訴我,代碼中的問題是什么。
st = "aaabba"/span>
n = len(st)
i =0
while i < n - 1:
count = 1 1
while (i < n-1 and st[i] == st[i 1] )。)
count =1
i = 1: count = 1.
i = 1print(st[i - 1] str(count), end=")
uj5u.com熱心網友回復:
問題出在第一個while回圈中。 代碼應該是:
st = "aaabba"。
n = len(st)
i =0
while i <n:
count = 1
while (i < n-1 and st[i] == st[i 1] )。)
count =1
i = 1: count = 1.
i = 1print(st[i - 1] str(count), end=")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/324442.html
標籤:
