結果

問題 No.275 中央値を求めよ
ユーザー tamane
提出日時 2019-04-05 19:34:05
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 572 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 28,160 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-13 00:35:17
合計ジャッジ時間 1,261 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 5 WA * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main(void) {
    int len,arraylen;
    int array[1001];

    scanf("%d", &len);
    for(int count=0; count<=len; count++) {
        scanf("%d", &array[count]);
    }

    arraylen = sizeof array / sizeof array[0];

    qsort(array, arraylen, sizeof(int), compare_int);
    if(arraylen % 2 == 1) {
        printf("%d\n", array[arraylen/2+1]);
    } else {
        printf("%d\n", (array[arraylen/2] + array[arraylen/2+1])/2);
    }
    return 0;
}
0