結果

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <cctype>
#include <typeinfo>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int num, a;
  double med;

  // 標準入力から、空白や改行で区切られた整数と文字列を読み込む。
  cin >> num;

  vector<int> data(num);

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

  sort(data.begin(), data.end());

  if(num%2==0){
    med = (data[num/2-1] + data[num/2])/2.0;
  }else{
    med = data[num/2];
  }
  cout << med << endl;
  return 0;
}
0