fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. map<char,int> freq;
  6. string t = "My name is mohammed arif, i read in class 5";
  7. for(int i=0;i<t.size();++i){
  8. if(freq.find(t[i]) == freq.end()){
  9. freq[t[i]] = 0;
  10. }
  11. freq[t[i]]++;
  12. }
  13. for(auto it = freq.begin(); it != freq.end();++it){
  14. cout << it->first << ": " << it->second << endl;
  15. }
  16. return 0;
  17. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
 : 9
,: 1
5: 1
M: 1
a: 5
c: 1
d: 2
e: 3
f: 1
h: 1
i: 4
l: 1
m: 4
n: 2
o: 1
r: 2
s: 3
y: 1