jeapedu 25 字符串两重循环习题2
2018-02-28 17:13
344 查看
链接: https://pan.baidu.com/s/1qZIwnz2 密码: n3fc
s = "hello jeapedkddu.com" head = "je" tail = "du" ph = 0 pt = 0 i = 0 while i < len(s) - len(head) + 1: # <=, 20-2=18, 0~19 -> 0~18 j = 0 ch = 0 while j < len(head): if s[i + j] == head[j]: ch += 1 j += 1 j = 0 ct = 0 while j < len(tail) and i + j < len(s): # pos 18 + 0/1/2 < 20 if s[i + j] == tail[j]: ct += 1 j += 1 if ch == len(head): ph = i if ct == len(tail): pt = i i += 1 print(ph,pt) sub = '' k = ph + len(head) while k < pt: sub += s[k] k += 1 print(sub)
相关文章推荐
- jeapedu 24 字符串与两重循环习题答案
- jeapedu 27 字符串与两重循环习题2图解
- jeapedu 14 两重循环习题2
- jeapedu 26 字符串与两重循环习题2答案
- jeapedu 20 字符串习题答案
- jeapedu 15 两重循环习题3
- jeapedu 23 字符串与两重循环
- jeapedu 13 两重循环习题1
- 字符串循环右移K位
- 循环-25. 求给定序列前N项和之三(15)
- [转]浅析“最小表示法”思想在字符串循环同构问题中的应用-HDU2609
- 【面试题25】字符串的排列
- jquery之each循环遍历的方法---split 分割字符串返回数组
- 字符串循环移动-高效优雅算法
- 我的ACM之路 7-25(字符串)
- PAT 1032. Sharing (25)(求俩个字符串的交点)
- C的一些简单习题(5)--两个字符串比较
- Python 将json字符串 进行列表化可循环
- 读书笔记--字符串循环移位
- c程序设计语言_习题1-16_自己编写getline()函数,接收整行字符串,并完整输出