fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <string.h>
  6.  
  7. std::vector<std::string> CountChar(char str[]){
  8. std::vector<std::string> vec;
  9. std::string s;
  10. int Len = strlen(str);
  11. int F = 0;
  12. int Buf = 0;
  13. std::sort(str, str + Len);
  14.  
  15. Buf = str[0];
  16.  
  17. for (int i = 0; i < Len; i++){
  18. if (Buf != str[i]){
  19. Buf = str[i];
  20. str[i] = '\0';
  21. s = (&str[F]);
  22. vec.push_back(s);
  23. str[i] = Buf;
  24. F = i;
  25. }
  26. }
  27. auto Fun = [](std::string& A, std::string& B){return A.size() < B.size(); };
  28. //std::sort(vec.begin(), vec.end(), Fun);//why not work? it work on vc2013!
  29.  
  30. for (int i = 0; i < vec.size(); i++){
  31. for (int j = i; j < vec.size(); j++){
  32. if (Fun(vec[i], vec[j])) std::swap(vec[i], vec[j]);
  33. }
  34. }
  35.  
  36. return vec;
  37. }
  38.  
  39. int main(){
  40. char str[] = "We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris.";
  41.  
  42. auto v = CountChar(str);// str[]'s inner to bloken.in function.
  43.  
  44. for (auto& s : v){
  45. std::cout << s[0] << ':' << s.size() << '[' << s << ']' << std::endl;
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
 :16[                ]
e:14[eeeeeeeeeeeeee]
r:8[rrrrrrrr]
a:7[aaaaaaa]
o:6[oooooo]
i:6[iiiiii]
t:6[tttttt]
n:4[nnnn]
s:4[ssss]
l:4[llll]
u:4[uuuu]
m:3[mmm]
g:3[ggg]
h:3[hhh]
p:3[ppp]
c:2[cc]
d:2[dd]
,:2[,,]
v:2[vv]
.:1[.]
f:1[f]
b:1[b]
::1[:]
W:1[W]
w:1[w]
y:1[y]