結果

問題 No.275 中央値を求めよ
ユーザー ub_nyaoiix
提出日時 2016-12-17 16:05:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 37 ms / 1,000 ms
コード長 404 bytes
コンパイル時間 1,109 ms
コンパイル使用メモリ 108,952 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-06-25 00:09:57
合計ジャッジ時間 3,528 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class Q0275
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());

		string[] num = Console.ReadLine().Split(' ');
		int[] a = new int[n];
		for (int i=0; i<n; i++)
		{
			a[i] = int.Parse(num[i]);
		}

		Array.Sort(a);

		float output;
		if(n%2 > 0)
		{
			output = a[n/2];
		}
		else
		{
			output = (float)(a[n/2] + a[n/2-1])/2;
		}

		Console.WriteLine(output);
	}
}
0