代码运行正常,输出看起来没问题。但我的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
感谢您的帮助! –