Respuesta :

Answer:

#include <iostream>

#include<map>//to inlude hashmap..

#include<string>

using namespace std;

int main() {

   string sa;//declaring a string s.

   map<char,int>m;// A hashmap of char type key and integer type value.

   cout<<"Enter the text"<<endl;

   cin>>sa;//taking input of the string..

   for(int i=0;i<sa.length();i++)

   {

       m[sa[i]]++;//increasing the count of character in the hashmap..

   }

   for(auto i:m)//iterating oveer the hashmap m

   {

       cout<<i.first<<" "<<i.second<<endl;//displaying the character and the count..

   }

return 0;

}

Explanation:

I have taken a hashmap m and a string s .I am taking input of text in the string s.The hashmap is of type key =Char and value = int to store the count.After that iterating over the string and updating the count in the hashmap of each character and then printing the count of each character..