Header Ads Widget

Count of Repeated characters

 Count of Repeated characters :-

Given a string , write a program to print the count of repeated characters .For better understanding see sample input output .

Sample input:

aabbaa
abbbc
aabcc
aaabbccaaad

Sample output :

3
1
2
4

Count of Repeated characters :-

The objective of the code is to write the program to find the number of repeated characters into string. 

Code(C++):-


#include <bits/stdc++.h>

using namespace std;

int main()
{
string line;
cin>>line;
int count=0;
int ans=0;
int l=line.length();
for(int i=0;i<l-1;i++)
{
if(line[i]==line[i+1])
{
count=1;
while(i<l-1 and line[i]==line[i+1])
i++;
}
if(count==1)
{
count=0;
ans++;
}
}
cout<<ans;
return 0;
}

Output:-

aabaacc
3

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments