結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2017-06-01 10:28:43 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 35 ms / 1,000 ms |
コード長 | 797 bytes |
コンパイル時間 | 792 ms |
コンパイル使用メモリ | 106,880 KB |
実行使用メモリ | 20,608 KB |
最終ジャッジ日時 | 2024-06-25 00:30:35 |
合計ジャッジ時間 | 3,149 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.
ソースコード
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace lecture{class Program{static void Main(string[] args){int a = 0;double result = 0;int n = int.Parse(Console.ReadLine());double[] data = Console.ReadLine().Trim().Split(' ').Select(x => double.Parse(x)).ToArray();Array.Sort(data);// 真ん中の計算a = n / 2;// 中央値の計算if (data.Length % 2 == 0){result = (data[a-1] + data[a]) / 2;}else{result = data[a];}Console.WriteLine(result);}}}