結果

問題 No.275 中央値を求めよ
ユーザー s1dim
提出日時 2015-09-13 10:24:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 513 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 54,968 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-06-24 23:16:42
合計ジャッジ時間 1,923 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
int main(){
    int n;
    int tmp;
    double a[1000000]={0};

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(a[i] > a[j]){
                tmp = a[j];
                a[j] = a[i];
                a[i] = tmp;
            }
        }
    }

    if(n % 2 == 0){
        cout << (a[n/2-1] + a[n/2])/2 << endl;
    } else {
        cout << a[n/2] << endl;
    }
}
0