結果

問題 No.275 中央値を求めよ
ユーザー 一ノ瀬卯月
提出日時 2019-03-04 15:54:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 418 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 65,408 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-23 13:30:35
合計ジャッジ時間 1,891 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	vector<int> arr;
	int a;
	float b;
	cin >> a;
	arr.resize(a);
	while (a > 0)
	{
		cin >> arr[a-1];
		a--;
	}

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

	if (arr.size() % 2 == 1)
	{
		b = (arr[arr.size() / 2]);
	}

	else
	{
		b = (float)(arr[arr.size() / 2] + (float)arr[(arr.size() / 2) - 1]) / 2;
	}

	cout << b << endl;
	return 0;
}
0