Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool cmp(pair<int, pair<string, int>>& x, pair<int, pair<string, int>>& y) {
- int marks1 = x.first, age1 = x.second.second, marks2 = y.first, age2 = y.second.second;
- string name1 = x.second.first, name2 = y.second.first;
- if (marks1 != marks2) return (marks1 > marks2);
- else if ((marks1 == marks2) && (age1 != age2)) return (age1 < age2);
- else return (name1 < name2);
- }
- int main() {
- //st marks -int|| st name -string|| st age-int
- int n; cin >> n;
- vector<pair<int, pair<string, int>>> v(n);
- for (int i = 0; i < n; i++) {
- int marks, age; string name;
- cin >> marks >> name >> age;
- v[i].first = marks;
- v[i].second.first = name;
- v[i].second.second = age;
- }
- sort(v.begin(), v.end(), cmp);
- for (int i = 0; i < n; i++) {
- cout << v[i].first << " " << v[i].second.first << " " << v[i].second.second << " " << endl;
- }
- //in case of multiple fields we will be doing sorting on the basis of first and then on second and so on,
- //in case of tie breakers
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement