結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2017-02-16 16:01:55 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 311 ms / 1,000 ms |
コード長 | 966 bytes |
コンパイル時間 | 3,746 ms |
コンパイル使用メモリ | 77,328 KB |
実行使用メモリ | 48,528 KB |
最終ジャッジ日時 | 2024-06-25 00:21:18 |
合計ジャッジ時間 | 14,190 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import java.util.Scanner; public class Q2 { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner kb=new Scanner(System.in); int n=kb.nextInt(); double ar[]=new double[n]; double num; for(int i=0;i<n;i++){ ar[i]=kb.nextDouble(); } //並べ替え for(int j=0;j<n;j++){ for(int i=0;i<n;i++){ if(i+1<n){ num=0; if(ar[i]>ar[i+1]){ num=ar[i]; ar[i]=ar[i+1]; ar[i+1]=num; }else{ continue; } }else{ break; } } } /* for(int i=0;i<n;i++){ System.out.printf("%d",ar[i]); } ちゃんと並べ替えられていることを確認*/ if(n%2==0){ double a=ar[n/2-1]+ar[n/2]; try{ System.out.printf("%f", a/2); }catch(NumberFormatException e){ System.out.printf("%f",a/2); } }else{ try{ System.out.printf("%f",ar[n/2]); }catch(NumberFormatException e){ System.out.printf("%f",ar[n/2]); } } } }