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 print
“Longest substring in alphabetical order is: beggh”
In the case of ties, print the first substring. For example, if s = ‘abcbcd’, then your program should print
“Longest substring in alphabetical order is: abc”
当然这其实只是个入门Python语言的题而已,不过毕竟是目前最难的一道,所以还是很兴奋的。
要点就是,Python里面的字符可以直接比较大小
顺便,按照这个课里面提交程序的惯例,s都是不定义的(测试的时候会加一句定义,类似于直接输入一个数据了吧)
1 | prev = 'a' |