Alphabetical Substrings
来源:互联网 发布:渡边琢斗 知乎 编辑:程序博客网 时间:2024/06/05 10: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: abcs='abcbcd'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
- Android自动化测试(UiAutomator)简要介绍
- 设计模式--单件模式Singleton(创建型)
- 无法访问存储导致down实例
- 多个泛型
- SharedPreferences存储读取数据
- Alphabetical Substrings
- 发送带附件的邮件怎样写
- Android WebRTC 音视频开发总结(一)
- MATLAB入门教程
- 使用uiautomator做UI测试
- C#中String与StringBuilder的区别
- Ruby 时间规范化函数strftime使用大全
- linux学习笔记之常用命令(-)
- 匿名管道实现进程信息交换