Advertisement
Guest User

Untitled

a guest
Jul 24th, 2021
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. // by Baratovich
  4.  
  5. // comparators:
  6. bool key_sort_in_descending_order (pair <string, pair <int, int>> a, pair <string, pair <int, int>> b) {
  7. return (a.first > b.first);
  8. }
  9.  
  10. bool first_value_sort_in_descending_order (pair <string, pair <int, int>> a, pair <string, pair <int, int>> b) {
  11. return a.second.first > b.second.first;
  12. }
  13.  
  14. bool second_value_sort_in_descending_order (pair <string, pair <int, int>> a, pair <string, pair <int, int>> b) {
  15. return a.second.second > b.second.second;
  16. }
  17.  
  18. signed main () {
  19. ios_base :: sync_with_stdio (0);
  20. cin.tie (0);
  21. cout.tie (0);
  22. vector <pair <string, pair <int, int>>> a;
  23. // filling the vector with different values for example
  24. for (int i = 0; i < 10; i++) {
  25. string s = "String";
  26. s += char (64 + i + 48);
  27. a.push_back(make_pair(s, make_pair(rand(), rand())));
  28. }
  29. // before any sorting:
  30. cout << "before any sorting:\n";
  31. for (auto i: a) {
  32. cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
  33. } cout << '\n';
  34.  
  35. // key_sort_in_descending_order:
  36. cout << "key_sort_in_descending_order:\n";
  37. sort (a.begin (), a.end (), key_sort_in_descending_order);
  38. for (auto i: a) {
  39. cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
  40. } cout << '\n';
  41.  
  42. // first_value_sort_in_descending_order:
  43. cout << "first_value_sort_in_descending_order:\n";
  44. sort (a.begin (), a.end (), first_value_sort_in_descending_order);
  45. for (auto i: a) {
  46. cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
  47. } cout << '\n';
  48.  
  49. // second_value_sort_in_descending_order:
  50. cout << "second_value_sort_in_descending_order:\n";
  51. sort (a.begin (), a.end (), second_value_sort_in_descending_order);
  52. for (auto i: a) {
  53. cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
  54. } cout << '\n';
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement