結果

問題 No.275 中央値を求めよ
ユーザー たつお
提出日時 2023-09-26 17:12:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 418 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 74,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 11:12:11
合計ジャッジ時間 1,591 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
//input
	int N;
	cin >> N;
	
	vector<int> a(N);
	for(int i=0;i<N;i++){ cin >> a.at(i); }
//calc
	double ans;
	
	sort(a.begin(),a.end());
	
	if(a.size() % 2 != 0){
		ans = (double)a.at(a.size() / 2);
	}else{
		ans = (double)(a.at(a.size() / 2) + a.at(a.size() / 2 - 1)) / 2;
	}
//output
	cout.precision(3);
	cout << ans;
}
0