language: C++11 (gcc-4.7.2)
date: 346 days 15 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
 
std::string cond(std::string const& in) {    
    unsigned long table[ 26 ] = { 0 }; /* known fixed charset */
    std::for_each(in.begin(), in.end(), [&table](char c){ table[ c - 'a' ]++; });
    std::stringstream out;
        for (size_t v = 0; v < 26; ++v) if (table[ v ]) out << table[ v ] << char(v + 'a');
        return out.str();
}
 
int main(){
    std::string in = "aaabbbbcccccdde";
    std::cout << cond(in);    
}