#include <stdio.h>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
bool UDgreater(int elem1, int elem2)
{
return elem1 > elem2;
}
int main()
{
std::string ch = "sdfdfgdfgdfhertwtuhfggrerrsdfdwed";
std::map<char, int> strMap;
for (int i = 0; i < ch.length(); i++)
{
char c = ch.at(i);
if (strMap.find(c) != strMap.end())
{
strMap.find(c)->second++;
}
else
{
strMap.insert(std::make_pair(c, 1));
}
}
std::vector<int> vecInt;
for (auto iter = strMap.begin(); iter != strMap.end(); iter++)
{
char tmp = iter->first;
printf_s("%c: %d \t", tmp, iter->second);
vecInt.push_back(iter->second);
}
printf_s("\n");
sort(vecInt.begin(), vecInt.end(), UDgreater);
for (int i = 0; i < vecInt.size(); i++)
{
printf_s("%d ", vecInt[i]);
}
return 0;
}
12-17
6756
06-27
684
10-20
4525
11-27
580
10-21
356