fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. char maxOccuringChar(string text)
  5. {
  6. int maxfreq = 0;
  7. char maxchar;
  8. map<char,int> freq;
  9. for (char c : text)
  10. {
  11. freq[c]++;
  12. if (freq[c] > maxfreq)
  13. {
  14. maxfreq = freq[c];
  15. maxchar = c;
  16. }
  17. }
  18. return maxchar;
  19.  
  20. }
  21. int main() {
  22. string text;
  23. cin >> text;
  24. cout << maxOccuringChar(text);
  25. }
Success #stdin #stdout 0s 5308KB
stdin
111222333
stdout
1