結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2018-04-19 15:58:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 185 ms / 1,000 ms |
コード長 | 869 bytes |
コンパイル時間 | 2,066 ms |
コンパイル使用メモリ | 75,112 KB |
実行使用メモリ | 54,984 KB |
最終ジャッジ日時 | 2024-06-25 01:15:37 |
合計ジャッジ時間 | 9,455 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import java.util.Arrays; import java.util.Scanner; public class Main{ public static void main(String[] args) { // int[] a1 = {1, 5, 2, 4, 7}; // int[] a2 =new int[a1.length]; // System.arraycopy(a1, 0, a2, 0, a1.length); // BubbleSort bs = new BubbleSort(a1); // bs.getArrayAsc(); // for(int i = 0; i < a1.length; i++) { // System.out.println(a1[i] + "/" + a2[i]); // } //System.out.println("数字の数"); Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int array[] = new int[N]; for(int i = 0; i < N; i++) { array[i] = scanner.nextInt(); } scanner.close(); //BubbleSort bs = new BubbleSort(array); //int[] array1 = bs.getArrayAsc(); Arrays.sort(array); if(N % 2 ==0) { double ans = (double)(array[N/2-1]+array[N/2])/2; System.out.println(ans); }else { System.out.println(array[(N+1)/2-1]); } } }