結果

問題 No.275 中央値を求めよ
ユーザー hamray
提出日時 2017-11-17 23:48:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 502 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 78,348 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-25 00:43:44
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
using namespace std;
int main(void){
    int N; cin >> N;
    double A;
    vector<double> v;
    for(int i = 0; i < N; i++){
        cin >> A;
        v.push_back(A);
    }
    sort(v.begin(), v.end());
    if(N % 2 != 0){
        cout << v[(N-1) / 2] << endl;
    }else{
        cout << (v[(N-1) / 2] + v[(N-1) / 2 + 1]) / 2 << endl;
    }
    return 0;
}
    
0