Counting rr

Problem:-

Given a string consisting of lower-case letters . Count the total number of substring ‘rr’ present in the given string.No substring should be counted twice.
Input
Given a string s consisting of lower-case letters.
Output
Print the total number of substring ‘rr’ present in the given string.
Constraints
1 ≤ strlen(s) ≤ 

105

SAMPLE INPUT
 
rrrabc
SAMPLE OUTPUT
 
2
Explanation

“rr” substring is present two times in given string.
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB

solution:-

#include<stdio.h>
void main()
{
     char s[100000];
     int sum=0;
     scanf(“%s”,s);
     for(int i=0;s[i+1];i++)
     {
        if(s[i]==‘r’)
        {
            if(s[i+1]==‘r’)
             sum++;
        }
     }
     printf(“%d”,sum);
}

Leave a Reply

Your email address will not be published.