Header Ads Widget

Program to print the characters with their frequency | unthinkable solutions

 Program to print the characters with their frequency :-

Given a string , write a Program to print the characters with their frequency .

Sample input:-

easycodingzone

Sample output:-

1a1c1d2e1g1i2n2o1s1y1z



Program to print the characters with their frequency

The objective of the code is to print the characters with their frequency .



Code:-

#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
cout<<"Enter a string"<<endl;
cin>>str;
map<char,int> m;
for(int i=0;i<str.size();i++)
{
m[str[i]]++;
}
for(auto ch:m)
{
cout<<ch.second<<ch.first;
}
return 0;
}

Output:-

Enter a string
easycodingzone
1a1c1d2e1g1i2n2o1s1y1z

Wipro :-

Infytq :-

Key Points;-

Hackerrank:-


C-tutorial:-

See more:-