結果
問題 |
No.275 中央値を求めよ
|
ユーザー |
![]() |
提出日時 | 2015-09-18 20:02:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 206 ms / 1,000 ms |
コード長 | 637 bytes |
コンパイル時間 | 3,431 ms |
コンパイル使用メモリ | 77,256 KB |
実行使用メモリ | 42,656 KB |
最終ジャッジ日時 | 2024-06-24 23:18:58 |
合計ジャッジ時間 | 11,304 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
package yuki_coder; import java.util.Scanner; public class No_275 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for(int i=0; i<a.length; i++){ a[i] = sc.nextInt(); } for(int i=0; i<a.length-1; i++){ for(int j=a.length-1; j>i; j--){ if(a[j] < a[j-1]){ int t = a[j]; a[j]=a[j-1]; a[j-1]=t; } } } if(n%2==1){ int b = (n+1)/2; System.out.println(a[b-1]); }else if(n%2==0){ double b = ((n+1.0)/2.0); int c = (int)((b - 0.5)-1); int d = (int)((b + 0.5)-1); double e = (a[c] + a[d])/2.0; System.out.println(e); } } }