fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. int main(){
  6. std::string str = "the quick brown fox jumps over the lazy dog";
  7. std::sort(str.begin(), str.end());
  8. std::string strcopy;
  9. std::unique_copy(str.begin(), str.end(), back_inserter(strcopy) );
  10. for(size_t i=0; i<strcopy.length(); ++i)
  11. std::cout << strcopy[i] << " = " << count(str.begin(), str.end(), strcopy[i]) << "\n";
  12. }
  13.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
  = 8
a = 1
b = 1
c = 1
d = 1
e = 3
f = 1
g = 1
h = 2
i = 1
j = 1
k = 1
l = 1
m = 1
n = 1
o = 4
p = 1
q = 1
r = 2
s = 1
t = 2
u = 2
v = 1
w = 1
x = 1
y = 1
z = 1