For 循环编程题
来源:互联网 发布:手机如何注册淘宝会员 编辑:程序博客网 时间:2024/06/15 18:48
Q:
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: begghA:curString = s[0]longest = s[0]for i in range(1, len(s)): if s[i] >= curString[-1]: curString += s[i] if len(curString) > len(longest): longest = curString else: curString = s[i]print 'Longest substring in alphabetical order is:', longest
思路整理:
初始化: 连续的字符串为s[0]; 最长的连续字符串是s[0]
如果s中的字符大于或等于连续字符串中的最后一个字符,则累加,并改变最长字符串的值;
否则重新设置连续字符串的首字符为s[i]
0 0
- For 循环编程题
- C#编程,for循环
- shell for循环编程
- shell编程--for循环
- 用 Python 编程 for 循环
- shell编程 for in 循环
- linux shell编程for循环
- shell编程 for in 循环
- shell编程 for in 循环
- 编程题:利用for循环打印 9*9 表?
- PHP编程----for循环的妙用
- C++编程实例-for循环结构
- shell 编程——for in 循环
- 求for 循环结构编程解决方案
- 【Java编程】之三种for循环
- shell 编程——for in 循环
- Shell 编程6(循环语句for)
- Shell编程—for循环总结【转】
- node---http模块,如何用node.js做简单的服务器环境http.createServer
- 利用Base64对文本进行加密解密操作
- HDU 5253 连接的管道(最小生成树)
- java数组中根据元素查找位置 索引
- poj 1556 线段相交 + dijstra
- For 循环编程题
- 用sax解析jsp页面时的问题
- android 7.0 app安装问题
- 数据表的创建
- 39.top10热门品类之自定义二次排序key
- (HTML5 )canvas 第八章
- Git仓库恢复
- POJ 2763 树链剖分+线段树维护区间和
- (转载)感知机模型