Statement: find the calculated frequency of characters in a string in c++ program
Input : Enter the String
programming
Output:
Program:
#include <iostream>
#include <unordered_map>
using namespace std;
void occurChar(string s)
{
unordered_map<char, int> m;
for (int i = 0; i < s.size(); i++)
{
m[s[i]]++;
}
cout << "Count the character " << endl;
for (auto j : m)
{
if (j.first > 0)
{
cout << j.first << " " << j.second << endl;
}
}
}
int main()
{
string str;
cout << "Enter the String " << endl;
cin >> str;
occurChar(str);
return 0;
}
0 Comments