fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <map>
  5.  
  6. int main()
  7. {
  8. const std::string s {"ffag,ddaf,asdf,qwefrty."};
  9.  
  10. std::map<char,bool> hasChar;
  11. std::map<char,int> charCount;
  12.  
  13. for( auto c : s )
  14. {
  15. if( c == ',' || c == '.' )
  16. {
  17. for( auto& p : hasChar )
  18. {
  19. ++charCount[p.first];
  20. }
  21. hasChar.clear();
  22. }
  23. else
  24. {
  25. hasChar[c] = true;
  26. }
  27. }
  28.  
  29. auto it = std::max_element( charCount.begin(), charCount.end(), [](const std::pair<char,int>& l, const std::pair<char,int>& r){ return l.second < r.second; });
  30. std::cout << it->first << std::endl;
  31. return 0;
  32. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
f