結果

問題 No.275 中央値を求めよ
ユーザー dododondon111
提出日時 2017-03-17 16:50:55
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 498 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-25 00:24:12
合計ジャッジ時間 2,134 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

int int_sort( const void * a , const void * b ) {
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}

int main(){
  int i,nx;
  int *x;

  scanf("%d",&nx);
  x = calloc(nx,sizeof(int));


  for(i=0;i<nx;i++){
    scanf("%d",&x[i]);
  }

  qsort(x,nx,sizeof(int),int_sort);

  if(nx%2==1) printf("%d",x[nx/2]);
  else printf("%f",(x[nx/2-1]+x[nx/2])/2.0);

  free(x);
  return 0;
}
0