Alphabetical Substrings
来源:互联网 发布:java web工程反编译 编辑:程序博客网 时间:2024/06/06 03:48
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, ifs = '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
s='azcbobobegghakl'count=1result=s[0]while s: newcount=1 newresult='' i=0 while i+1<len(s): if ord(s[i])<=ord(s[i+1]): newresult+=s[i+1] newcount+=1 else: break i+=1 if newcount>count: count=newcount result=s[0]+newresult s=s[i+1:]print result
0 0
- Alphabetical Substrings
- Alphabetical Substrings
- Python PS1-3 Alphabetical Substrings
- MITx: 6.00.1x Alphabetical Substrings (python)
- Substrings
- Substrings
- Substrings
- Substrings
- Substrings
- Substrings
- Substrings
- Seven-Bit Alphabetical
- Alphabetical list of IDC functions
- POJ1226 Substrings
- HDOJ1238 Substrings
- poj1226 Substrings
- Substrings hdu
- HDU Substrings
- curl命令解析
- 一个女大学生的代码学习之路(一)
- Android中自定义View的MeasureSpec介绍及使用详解
- 最大和
- 台湾9名警员轻罚超载货车被依贪污罪起诉
- Alphabetical Substrings
- python 正则表达式介绍
- 一个女大学生的代码学习之路(一)
- 解答Google的一道面试题
- 待验证问题和注意点
- 【动态更新】javascript小技巧随记
- StartSSL免费SSL证书成功申请-HTTPS让访问网站更安全
- ScrollView嵌套ListView高度问题解决(工具)
- 设计模式-- 观察者模式Observer(对象行为型)