Skip to content

Instantly share code, notes, and snippets.

@wallstop
Created August 31, 2014 21:55
Show Gist options
  • Save wallstop/76de1d6739e2ec2e4e04 to your computer and use it in GitHub Desktop.
Save wallstop/76de1d6739e2ec2e4e04 to your computer and use it in GitHub Desktop.
std::string temp = "bbbbcdfagg";
std::sort(temp.begin(), temp.end());
int count = 1;
char last = *temp.cbegin();
std::map<int, std::string> tempMap;
for (auto&& itr = temp.cbegin()+1; itr != temp.cend(); ++itr)
{
if (*itr == last)
{
++count;
if(itr+1 != temp.cend())
continue;
}
tempMap[count] += last;
count = 1;
last = *itr;
}
for (auto && thing : tempMap)
{
std::cout << thing.first << " " << thing.second << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment