Guest User

Untitled

a guest
Jan 7th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #Problem 3
  2. #15/15 points (graded)
  3. #Assume s is a string of lower case characters.
  4. #Write a program that prints the longest substring of s in which the letters occur in alphabetical order.
  5. #For example, if s = 'azcbobobegghakl', then your program should print
  6. #Longest substring in alphabetical order is: beggh
  7. #In the case of ties, print the first substring. For example, if s = 'abcbcd', then your program should print
  8. #Longest substring in alphabetical order is: abc
  9. #Note: This problem may be challenging. We encourage you to work smart.
  10. #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.
  11. #If you have time, come back to this problem after you've had a break and cleared your head.
  12. #code Editor
  13. length=0
  14. st=s[0]
  15. lar=s[0]
  16. for i in range(len(s)-1):
  17. if(s[i+1]>=s[i]):
  18. st +=s[i+1]
  19. #check the length is max or not...cv
  20. if len(st)>length:
  21. length=len(st)
  22. lar=st
  23. #if upper if not statisfy...
  24. else:
  25. st=s[i+1]
  26. #print the result
  27. print("largest no is :"+lar)
Add Comment
Please, Sign In to add comment