Advertisement
fooker

Comparators

Nov 17th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool cmd(int x, int y, int z){
  4.     return abs(x-y)<=abs(y-z);
  5. }
  6. int main() {
  7.     int t;
  8.     cin>>t;
  9.     while(t--){
  10.         int n;
  11.         cin>>n;
  12.         int a[n];
  13.         for (int i=0; i<n; i++) cin>>a[i];
  14.         sort(a,a+n,cmd);
  15.         for (int i=0; i<n; i++){
  16.             cout<<a[i]<<" ";
  17.         }
  18.         cout<<"\n";
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement