sabertooth09

Untitled

Jun 11th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pi acos(-1)
  5.  
  6. void sortLU(ll a[],ll n,ll b[])
  7. {
  8.     //to sort lower to upper
  9.     ll i,j;
  10.     for(i=0; i<n; i++)
  11.     {
  12.         for(j=0; j<n; j++)
  13.         {
  14.             if(a[i]<a[j]|| (a[i]==a[j] && b[i]>b[j]))
  15.             {
  16.                 swap(a[i],a[j]);
  17.                 swap(b[i],b[j]);
  18.             }
  19.         }
  20.     }
  21. }
  22.  
  23. int main()
  24. {
  25.     int test;
  26.     cin>>test;
  27.     while(test--)
  28.     {
  29.         ll n;
  30.         cin>>n;
  31.         ll a[n],b[n];
  32.         for(ll i=0; i<n; i++)
  33.         {
  34.             cin>>a[i]>>b[i];
  35.         }
  36.         sortLU(a,n,b);
  37.         for(ll i=0; i<n; i++)
  38.         {
  39.             cout<<a[i]<<" "<<b[i]<<endl<<endl;
  40.         }
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment