统计字符在字符串中第n次出现的位置

Posted deranuid

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了统计字符在字符串中第n次出现的位置相关的知识,希望对你有一定的参考价值。

ss=input()
n=int(input())
c=input()

cnt= list(ss).count(c)
if cnt<n:
    print(‘no‘)
else:
    lt=ss.split(c)
    sum=0
    for i in range(n):
        sum+=len(lt[i])+1
    print(sum)

以上是关于统计字符在字符串中第n次出现的位置的主要内容,如果未能解决你的问题,请参考以下文章