Facebook
From Dilwar Hossain, 1 Year ago, written in C++.
Embed
Download Paste or View Raw
Hits: 127
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. char max_freq_char(string s){
  4.     map<char,int>mp;
  5.     int i, len=s.size();
  6.     for(i=0; i<len; i++)
  7.     {
  8.         mp[s[i]]++;
  9.     }
  10.     int res = -1;
  11.     char ans;
  12.     for(auto x : mp)
  13.     {
  14.         if(res < x.second)
  15.         {
  16.             res = x.second;
  17.             ans = x.first;
  18.         }
  19.     }
  20.     return ans;
  21. }
  22. int main()
  23. {
  24.     string s;
  25.     cin >> s;
  26.     cout<<max_freq_char(s)<<"\n";
  27. }