fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7. string s = "ala ma kota";
  8. map<char, size_t> counts;
  9. for (auto& x : s) ++counts[x];
  10.  
  11. for (auto& x : counts) cout << x.first << " - " << x.second << "\n";
  12. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
  - 2
a - 4
k - 1
l - 1
m - 1
o - 1
t - 1