Count 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.

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);
}


One thought on “Count rr

Leave a Reply

Your email address will not be published.