jeapedu 25 字符串两重循环习题2

本文提供了一道来自Jeapedu的关于字符串处理的两重循环练习题目,通过链接分享了详细的解题资源,帮助学习者提升编程技能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接: 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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值