結果

問題 No.275 中央値を求めよ
ユーザー コーヒー太郎
提出日時 2020-05-13 12:04:02
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 740 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 30,592 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-14 15:32:52
合計ジャッジ時間 1,337 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 25 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(void){
    char c[6];
    int N, M;
    int *p;
    
    fgets(c, sizeof(c), stdin);
    N = atoi(c);

    
    p = (int *)malloc(sizeof(int) * N);
    for(int i = 0; i < N; i++) scanf("%d", &p[i]);

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N - i; j++){
            if(p[j] > p[j + 1]){
                M = p[j];
                p[j] = p[j + 1];
                p[j + 1] = M;
            }
        }
    }
    
    if(N % 2 == 0){
        M = p[N / 2] + p[N / 2 - 1];
        if(M % 2 == 0){
            printf("%d\n", M / 2);
        }else{
            printf("%.1f\n", M / 2.0);
        }
    }else{
        printf("%d\n", p[N / 2]);
    }
    
    free(p);
    return 0;
}
0