Advertisement
wojiaocbj

L

Jun 9th, 2022
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. long long arr[1024] = { 0 }, m;
  4. int compare(const void *p, const void *q){
  5.     long long a = *(long long *)p, b = *(long long *)q;
  6.     long long d1 = llabs(a - m), d2 = llabs(b - m);
  7.     if(d1 > d2){
  8.         return 1;
  9.     }
  10.     else if(d1 < d2){
  11.         return -1;
  12.     }
  13.     else{
  14.         if(a < b){
  15.             return -1;
  16.         }
  17.         else if(a > b){
  18.             return 1;
  19.         }
  20.         else{
  21.             return 0;
  22.         }
  23.     }
  24. }
  25. int main(){
  26.     int n, i;
  27.     scanf("%d%lld", &n, &m);
  28.     for(i = 0; i < n; i++){
  29.         scanf("%lld", arr + i);
  30.     }
  31.     qsort(arr, n, sizeof(long long), compare);
  32.     for(i = 0; i < n; i++){
  33.         printf("%lld\n", arr[i]);
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement