結果

問題 No.275 中央値を求めよ
ユーザー pirozhki
提出日時 2018-05-28 12:30:32
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 531 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 72,436 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-25 01:33:07
合計ジャッジ時間 2,235 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

int main(){
    int n;
    std::vector<int> input;
    
    std::cin >> n;
    for(int i=0; i < n; i++){
        int x;
        std::cin >> x;
        input.push_back(x);
    }
    
    std::sort(input.begin(), input.end());    
    
    std::cout << std::fixed << std::setprecision(1);
    if(n%2==0){
        std::cout << (input[n/2-1]+input[n/2])/2. << std::endl;
    } else {
        std::cout << input[n/2] << std::endl;
    }
    
    return 0;
}
0