Last active
October 28, 2016 13:42
-
-
Save fpdjsns/4ee81897968d864fe1928ac231ce8e94 to your computer and use it in GitHub Desktop.
pair descending order using sort function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<algorithm> | |
using namespace std; | |
bool compare(const pair<int, int>& a, const pair<int, int>& b) | |
{ | |
//If the first number is same | |
if (a.first == b.first) | |
return a.second > b.second; //The second number in Descending order | |
return a.first > b.first; //The first number of bigger numbers to move forward -> Descending order | |
} | |
int main() | |
{ | |
int N; | |
pair<int,int> arr[1000]; | |
cin >> N; | |
for (int i = 0; i < N; i++) | |
{ | |
cin >> arr[i].first >> arr[i].second; | |
} | |
//Descending order | |
sort(arr, arr + N, compare); | |
cout << endl; | |
for (int i = 0; i < N; i++) | |
cout << arr[i].first << " " << arr[i].second << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment