代碼運行正常,輸出看起來沒問題。但我的print
是裏面的for循環,這讓我懷疑的編碼是正確的:編寫一個程序,打印s中按字母順序排列的字母的最長子串
s = 'azcbobobegghakl'
i = 0
increase = 0
longest = 1
for i in range(len(s) - 1):
if s[i+1] >= s[i]:
increase +=1
else:
if increase > longest:
longest = increase
print ("
Longest substring in alphabetical order is:"+""+s[i-longest:i+1])
increase =0
感謝您的幫助! –