Character B follows A ID:225


Given a string S and two characters A, B the program must print the number of occurrences where A is followed by B.

Boundary Conditions:
Length of the string S is between 2 and 200.

Input Format:
First line will contain the string value S.
Second line will contain the value of A.
Third line will contain the value of B.

Output Format:
First line will contain the integer which represents the number of occurrences in sring S where A is followed by B
 

Sample Input/Output:

Example 1:
Input:
malayalam
a
l

Output:
2

Explanation:
The two occurrences where a is followed by l is as highlighted below.

Example 2:
Input:
engine
e
n

Output:
1


PROGRAM IN C:

#include<stdio.h>

#include <stdlib.h>


int main()

{

char str[1000];

char first[2],last[2];

int count=0;

scanf("%s",str);

scanf("%s",first);

scanf("%s",last);


for(int i=0;i<strlen(str);i++)

if(str[i]==first[0]&&str[i+1]==last[0])

count++;


printf("%d",count);



}

Comments

Popular Posts