题解 | #重复出现的字符串#

重复出现的字符串

https://www.nowcoder.com/practice/74a1dcc46607402780b6f6fc30241b2d

target = input()
patten = input()
index, count, i = -1, 0, 0
while i < len(target):
    if target[i] == patten[0] and i + len(patten) <= len(target):
        flag = True
        for j in range(len(patten)):
            if target[i+j] != patten[j]:
                flag = False
                break
        if flag == True:
            count += 1
            if count == 1:
                index = i
            i = i + len(patten)-1
    i += 1
            
print(count)
print(index)
不知道有没有内置函数可以直接用,我这是一遍循环来查找的
#Python#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务