-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcomparitorfunction.cpp
More file actions
45 lines (38 loc) · 985 Bytes
/
comparitorfunction.cpp
File metadata and controls
45 lines (38 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
// bool should_i_swap(int a,int b){
// if(a>b)
// return true;
// return false;
// }
bool should_i_swap(pair<int,int> a,pair<int,int> b){
// if(a.first != b.first){
// if(a.first <b.first)
// return true;
// return false;
// }else{
// if(a.second> b.second)
// return true;
// return false;
// }
if(a.first !=b.first)
return a.first<b.second;
return a.second >b.second ;
}
int main(){
int n;
cin>>n;
vector<pair<int,int>>a(n);
for(int i=0;i<n;i++)
cin>>a[i].first>>a[i].second;
// for(int i=0;i<n;i++){
// for(int j=i+1;j<n;j++){
// if(should_i_swap(a[i], a[j]))
// swap(a[i],a[j]);
// }
// }
sort(a.begin(), a.end(),should_i_swap);
for(int i=0;i<n;i++)
cout<<a[i].first<<" "<<a[i].second<<" "<<endl;
}