結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー nanatutmc
提出日時 2019-09-13 00:57:37
言語 C11(gcc12 gnu拡張)
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=gnu11 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 720 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 112 ms
コンパイル使用メモリ 33,388 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:21:06
合計ジャッジ時間 1,144 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:3:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
    3 | main() {
      | ^~~~
main.c: In function ‘main’:
main.c:9:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     scanf("%d", &count);
      |     ^~~~~~~~~~~~~~~~~~~
main.c:11:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d", &(num[i]));
      |         ^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <stdio.h>

main() {
    int min = -1000, max = 1000;
    
    int count;
    int num[1000];
    
    scanf("%d", &count);
    for (int i=0; i<count; i++)
        scanf("%d", &(num[i]));
    
    // bubble sort
    while (1) {
        int flag = 0;
        for (int i=0; i<count-1; i++) {
            if (num[i] > num[i+1]) {
                int value = num[i];
                num[i] = num[i+1];
                num[i+1] = value;
                
                flag = 1;
            }
        }
        
        if (flag == 0)
            break;
    }
    
    if (count % 2 == 1) {
        printf("%d\n", num[count/2]);
    } else {
        printf("%f\n", (((float)num[count/2]) + num[count/2-1])/2);
    }
}
0