結果

問題 No.275 中央値を求めよ
ユーザー コーヒー太郎
提出日時 2020-05-13 12:45:03
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 807 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 15:33:42
合計ジャッジ時間 1,220 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(void){
    char c[6];
    int N, M;
    int *p;
    char dummy;
    
    /*
    fgets(c, sizeof(c), stdin);
    N = atoi(c);
    */
    scanf("%d", &N);
    

    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 - 1; 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