結果

問題 No.490 yukiソート
ユーザー 37zigen37zigen
提出日時 2017-03-10 23:01:25
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 729 bytes
コンパイル時間 2,693 ms
コンパイル使用メモリ 86,320 KB
実行使用メモリ 59,204 KB
最終ジャッジ日時 2024-06-24 10:19:28
合計ジャッジ時間 10,865 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
		}
		int max = -1;
		for (int i = 0; i < n; ++i) {
			max = Math.max(i, a[i]);
		}
		boolean f = (a[n - 1] == max);
		Arrays.sort(a);
		if (f) {
			int d = a[n - 1];
			a[n - 1] = a[n - 2];
			a[n - 1] = d;
		}
		for (int i = 0; i < n; ++i) {
			System.out.print(a[i] + (i == n - 1 ? "\n" : " "));
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0