您的位置:首页 > 其它

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: