結果

問題 No.927 Second Permutation
ユーザー htensaihtensai
提出日時 2019-12-07 11:04:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 72,172 KB
実行使用メモリ 59,384 KB
最終ジャッジ日時 2023-08-26 05:20:12
合計ジャッジ時間 7,782 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
56,468 KB
testcase_01 AC 101 ms
55,964 KB
testcase_02 AC 106 ms
55,792 KB
testcase_03 AC 112 ms
55,916 KB
testcase_04 AC 112 ms
55,784 KB
testcase_05 AC 109 ms
55,496 KB
testcase_06 AC 110 ms
55,684 KB
testcase_07 AC 104 ms
55,888 KB
testcase_08 AC 148 ms
56,020 KB
testcase_09 AC 114 ms
56,208 KB
testcase_10 AC 170 ms
56,216 KB
testcase_11 AC 182 ms
58,712 KB
testcase_12 AC 167 ms
56,020 KB
testcase_13 AC 117 ms
55,868 KB
testcase_14 AC 166 ms
56,548 KB
testcase_15 AC 165 ms
57,116 KB
testcase_16 AC 184 ms
58,992 KB
testcase_17 AC 189 ms
59,024 KB
testcase_18 AC 187 ms
59,204 KB
testcase_19 AC 186 ms
58,980 KB
testcase_20 AC 190 ms
58,716 KB
testcase_21 AC 181 ms
58,628 KB
testcase_22 AC 179 ms
59,384 KB
testcase_23 AC 186 ms
58,740 KB
testcase_24 AC 169 ms
56,376 KB
testcase_25 AC 166 ms
54,684 KB
testcase_26 AC 146 ms
56,200 KB
testcase_27 AC 161 ms
56,136 KB
testcase_28 AC 182 ms
56,924 KB
testcase_29 AC 181 ms
56,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int length = arr.length;
		Arrays.sort(arr);
		char max = arr[length - 1];
		for (int i = 0; i < length - 1; i++) {
		    if (arr[i] == max || (i == length - 2 && arr[i] == '0')) {
		        break;
		    }
		    if (arr[i] == arr[i + 1]) {
		        continue;
		    }
		    char tmp = arr[i];
		    arr[i] = arr[i + 1];
		    arr[i + 1] = tmp;
		    StringBuilder sb = new StringBuilder(new String(arr));
		    sb.reverse();
		    System.out.println(sb);
		    return;
		}
		System.out.println(-1);
   }
}

0