fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. struct Entry
  8. {
  9. string Word;
  10. int Count;
  11.  
  12. Entry(const string& word, int count)
  13. : Word(word), Count(count)
  14. {
  15. }
  16. };
  17.  
  18. int main() {
  19. vector<Entry> entries = {{"hello", 2}, {"world", 8}, {"hi", 20}, {"connie", 10}};
  20.  
  21. sort(entries.begin(), entries.end(),
  22. [](const Entry& a, const Entry& b)
  23. {
  24. return a.Count > b.Count;
  25. }
  26. );
  27.  
  28. for (const auto& e : entries)
  29. {
  30. cout << e.Word << ": " << e.Count << '\n';
  31. }
  32. }
  33.  
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
hi: 20
connie: 10
world: 8
hello: 2