Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- // by Baratovich
- // comparators:
- bool key_sort_in_descending_order (pair <string, pair <int, int>> a, pair <string, pair <int, int>> b) {
- return (a.first > b.first);
- }
- bool first_value_sort_in_descending_order (pair <string, pair <int, int>> a, pair <string, pair <int, int>> b) {
- return a.second.first > b.second.first;
- }
- bool second_value_sort_in_descending_order (pair <string, pair <int, int>> a, pair <string, pair <int, int>> b) {
- return a.second.second > b.second.second;
- }
- signed main () {
- ios_base :: sync_with_stdio (0);
- cin.tie (0);
- cout.tie (0);
- vector <pair <string, pair <int, int>>> a;
- // filling the vector with different values for example
- for (int i = 0; i < 10; i++) {
- string s = "String";
- s += char (64 + i + 48);
- a.push_back(make_pair(s, make_pair(rand(), rand())));
- }
- // before any sorting:
- cout << "before any sorting:\n";
- for (auto i: a) {
- cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
- } cout << '\n';
- // key_sort_in_descending_order:
- cout << "key_sort_in_descending_order:\n";
- sort (a.begin (), a.end (), key_sort_in_descending_order);
- for (auto i: a) {
- cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
- } cout << '\n';
- // first_value_sort_in_descending_order:
- cout << "first_value_sort_in_descending_order:\n";
- sort (a.begin (), a.end (), first_value_sort_in_descending_order);
- for (auto i: a) {
- cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
- } cout << '\n';
- // second_value_sort_in_descending_order:
- cout << "second_value_sort_in_descending_order:\n";
- sort (a.begin (), a.end (), second_value_sort_in_descending_order);
- for (auto i: a) {
- cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
- } cout << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement