Advertisement
cd62131

Median

Feb 22nd, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 100000
  4. int compare_int(const void *p1, const void *p2) {
  5.   return *(int *) p1 - *(int *) p2;
  6. }
  7. int main(void) {
  8.   int n = 0, d, v[N];
  9.   while (~scanf("%d", &v[n++]))
  10.     ;
  11.   n--;
  12.   qsort(v, n, sizeof(int), compare_int);
  13.   if (v[0] - v[n / 2] > v[n - 1] - v[n / 2]) printf("%d\n", v[0]);
  14.   else printf("%d\n", v[n - 1]);
  15.   return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement