結果

問題 No.275 中央値を求めよ
ユーザー xvfz57
提出日時 2019-10-26 22:04:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 521 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 65,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 18:56:25
合計ジャッジ時間 2,067 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;


int main(){
  int numlen;
  int num;
  vector<int> num_v;
  cin >> numlen;
  for (int i = 0;i < numlen;i++) {
    /* code */
    cin >> num;
    num_v.push_back(num);
  }
  sort(num_v.begin(), num_v.end());
  if (num_v.size()%2){
    //cout << num_v.size()%2<< endl;
    cout << num_v[num_v.size()/2]<< endl;
  }else{
    //cout << num_v.size()/2<< endl;
    cout << (num_v[num_v.size()/2 - 1] + num_v[num_v.size()/2])/2.0 << endl;
  }
}
0