結果

問題 No.275 中央値を求めよ
ユーザー Torin3600
提出日時 2016-05-19 12:01:12
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 352 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 65,136 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-24 23:49:31
合計ジャッジ時間 1,657 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main(){
	vector<double> v;
	int n,d;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> d;
		v.push_back(d);
	}
	sort(v.begin(), v.end());
	if (n % 2 == 1){
		n /= 2;
		cout << v[n] << endl;
	}
	else{
		n /= 2;
		cout << (v[n] + v[n - 1]) / 2 << endl;
	}
	return 0;
}
0