結果

問題 No.275 中央値を求めよ
ユーザー コーヒー太郎コーヒー太郎
提出日時 2020-05-13 10:53:27
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 15:28:52
合計ジャッジ時間 1,338 ms
ジャッジサーバーID
(参考情報)
judge3 / 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", M / 2);
        }else{
            printf("%.1f", (float)M / (float)2);
        }
    }else{
        printf("%d", p[N / 2]);
    }
    
    
    return 0;
}
0