fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <sstream>
  5.  
  6. std::string cond(std::string const& in) {
  7. unsigned long table[ 26 ] = { 0 }; /* known fixed charset */
  8. std::for_each(in.begin(), in.end(), [&table](char c){ table[ c - 'a' ]++; });
  9. std::stringstream out;
  10. for (size_t v = 0; v < 26; ++v) if (table[ v ]) out << table[ v ] << char(v + 'a');
  11. return out.str();
  12. }
  13.  
  14. int main(){
  15. std::string in = "aaabbbbcccccdde";
  16. std::cout << cond(in);
  17. }
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
3a4b5c2d1e