結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー dododondon111
提出日時 2017-03-17 16:50:55
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 498 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 196 ms
コンパイル使用メモリ 39,904 KB
最終ジャッジ日時 2026-02-21 23:32:28
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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