fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int main() {
  8. string s;
  9. int h[256] = {0};
  10. cin>>s;
  11.  
  12. // maintaining a dictionary/hash mapped array
  13. // to store the frequencies of all the characters of the string
  14. for(int i=0;i<s.length();i++)
  15. {
  16. h[s[i]-'a'] += 1;
  17. }
  18.  
  19. int mx = 0;
  20. char mxi;
  21.  
  22. for(int i=0;i<256;i++)
  23. {
  24. if(h[i]>mx)
  25. {
  26. mx = h[i];
  27. mxi = i + 'a';
  28. }
  29. }
  30. cout<<mx<<" "<<mxi<<endl;
  31. return 0;
  32. }
Success #stdin #stdout 0s 5640KB
stdin
output
stdout
2 t