結果

問題 No.275 中央値を求めよ
ユーザー snrnsidy
提出日時 2021-07-18 23:57:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 469 bytes
コンパイル時間 1,795 ms
コンパイル使用メモリ 198,464 KB
最終ジャッジ日時 2025-01-23 03:16:10
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, t;
	vector <int> v;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> t;
		v.push_back(t);
	}

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

	if (n % 2 == 1)
	{
		cout << v[n / 2] << '\n';
	}
	else
	{
		int sum = v[(n / 2) - 1] + v[(n / 2)];
		if (sum % 2 == 0)
		{
			cout << sum / 2 << '\n';
		}
		else
		{
			cout << sum / 2 << ".5" << '\n';
		}
	}
	return 0;
}
0