Position statistical character in the string that appears in the n-th

Enter a string s, n and a number a character c, the statistical character c in the string s occurs in the n-th

Input formats:

Enter the three lines. Line 1 is the string s, the second row is a number n, the third row is being sought character c.

Output formats:

Position of the n-th character in the string values. If the string does not exist in the first n characters c, print out the 'no'

Sample input:

abcabcabc
2
a
 

Sample output:

4
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)

  

Guess you like

Origin www.cnblogs.com/SkystarX/p/12334058.html