Assume
s is a string of lower case characters.Write a program that prints the longest substring of
s in which the letters occur in alphabetical order. For example, if s = 'azcbobobegghakl', then your program should printLongest substring in alphabetical order is: begghIn the case of ties, print the first substring. For example, if
s = 'abcbcd', then your program should printLongest substring in alphabetical order is: abcNote: This problem may be challenging. We encourage you to work smart. If you've spent more than a few hours on this problem, we suggest that you move on to a different part of the course. If you have time, come back to this problem after you've had a break and cleared your head.
s=str(input('Please enter your string: ')).lower()
letter=str()
i=0
length=len(s)
print (length)
for i in range (len(s)-1):
if s[i] < s[i+1] :
letter+=s[i]
print (letter)
elif s[i] >= s[i+1] :
break
print (letter)
No comments:
Post a Comment