Friday, February 1, 2019

Number of Occurences of a Character

  • Problem Description

    Write a program find the number of occurrences of a character in a given string.
    Input:
    First line is the string, s
    Second line is the character, c
    Output:
    An integer, i.e. the number of occurrences of c in s.
  • CODING ARENA
  • a=input()
    b=input()
    x=len(a)
    count=0
    for i in range(x):
        if(b in a[i]):
            count+=1
    print(count)
  • Test Case 1

    Input (stdin)
    welcome
    
    w
    
    
    Expected Output
    1
  • Test Case 2

    Input (stdin)
    tamilnadu
    
    a
    
    
    Expected Output
    2

No comments:

Post a Comment