题解 | #统计回文#

统计回文

https://www.nowcoder.com/practice/9d1559511b3849deaa71b576fa7009dc

import sys
import copy

data=sys.stdin.readlines()
key=data[1].strip("\n")
l=list(data[0])
l.remove("\n")


def ishuiwen(l):
    i=0
    j=len(l)-1
    while i < len(l):
        if i>=j:
            return True
        if j>i and l[i]!=l[j]:
            return False
        i=i+1
        j=j-1

count=0

for i in range(len(l)+1):
    sax=copy.deepcopy(l)
    sax.insert(i,key)
    p="".join(sax)
    p=list(p)
    if ishuiwen(p):
        count=count+1

print(count)

全部评论

相关推荐

牛客92804383...:在他心里你已经是他的员工了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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