fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <map>
  4. #include <vector>
  5.  
  6. int main() {
  7. std::map<char, int> m{{'a', 5},
  8. {'b', 5},
  9. {'f', 3},
  10. {'k', 8},
  11. {'m', 5},
  12. {'w', 8},
  13. {'a', 8},
  14. {'c', 8},
  15. {'z', 1}};
  16.  
  17. std::vector<std::pair<char, int>> v{m.begin(), m.end()};
  18.  
  19. std::stable_sort(v.begin(), v.end(), [](const auto& l, const auto& r) {
  20. return l.second > r.second;
  21. });
  22.  
  23. for (const auto& item : v) {
  24. std::cout << item.first << " " << item.second << std::endl;
  25. }
  26. }
  27.  
Success #stdin #stdout 0s 3280KB
stdin
Standard input is empty
stdout
c 8
k 8
w 8
a 5
b 5
m 5
f 3
z 1