#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
std::vector<std::string> CountChar(char str[]){
std::vector<std::string> vec;
std::string s;
int Len = strlen(str);
int F = 0;
int Buf = 0;
std::sort(str, str + Len);
Buf = str[0];
for (int i = 0; i < Len; i++){
if (Buf != str[i]){
Buf = str[i];
str[i] = '\0';
s = (&str[F]);
vec.push_back(s);
str[i] = Buf;
F = i;
}
}
auto Fun = [](std::string& A, std::string& B){return A.size() < B.size(); };
//std::sort(vec.begin(), vec.end(), Fun);//why not work? it work on vc2013!
for (int i = 0; i < vec.size(); i++){
for (int j = i; j < vec.size(); j++){
if (Fun(vec[i], vec[j])) std::swap(vec[i], vec[j]);
}
}
return vec;
}
int main(){
char str[] = "We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris.";
auto v = CountChar(str);// str[]'s inner to bloken.in function.
for (auto& s : v){
std::cout << s[0] << ':' << s.size() << '[' << s << ']' << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nLmg+CgpzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4gQ291bnRDaGFyKGNoYXIgc3RyW10pewoJc3RkOjp2ZWN0b3I8c3RkOjpzdHJpbmc+IHZlYzsKCXN0ZDo6c3RyaW5nIHM7CglpbnQgTGVuID0gc3RybGVuKHN0cik7CglpbnQgRiA9IDA7CglpbnQgQnVmID0gMDsKCXN0ZDo6c29ydChzdHIsIHN0ciArIExlbik7CgoJQnVmID0gc3RyWzBdOwoKCWZvciAoaW50IGkgPSAwOyBpIDwgTGVuOyBpKyspewoJCWlmIChCdWYgIT0gc3RyW2ldKXsKCQkJQnVmID0gc3RyW2ldOwoJCQlzdHJbaV0gPSAnXDAnOwoJCQlzID0gKCZzdHJbRl0pOwoJCQl2ZWMucHVzaF9iYWNrKHM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