結果

問題 No.39 桁の数字を入れ替え
ユーザー htensaihtensai
提出日時 2019-12-07 10:03:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 113 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 71,664 KB
実行使用メモリ 56,260 KB
最終ジャッジ日時 2023-08-26 02:50:18
合計ジャッジ時間 4,934 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
56,008 KB
testcase_01 AC 107 ms
56,136 KB
testcase_02 AC 113 ms
56,196 KB
testcase_03 AC 105 ms
56,176 KB
testcase_04 AC 102 ms
55,924 KB
testcase_05 AC 103 ms
56,204 KB
testcase_06 AC 103 ms
56,016 KB
testcase_07 AC 107 ms
55,944 KB
testcase_08 AC 105 ms
56,052 KB
testcase_09 AC 106 ms
56,088 KB
testcase_10 AC 106 ms
55,732 KB
testcase_11 AC 108 ms
55,804 KB
testcase_12 AC 106 ms
56,260 KB
testcase_13 AC 108 ms
55,812 KB
testcase_14 AC 106 ms
56,088 KB
testcase_15 AC 108 ms
56,092 KB
testcase_16 AC 101 ms
56,152 KB
testcase_17 AC 101 ms
55,888 KB
testcase_18 AC 104 ms
55,948 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();
		for (int j = 9; j > 0; j--) {
		    boolean hasFinish = false;
    		int maxIdx = 0;
    		for (int i = 0; i < arr.length; i++) {
    		    if (j == arr[i] - '0') {
    		        maxIdx = i;
    		    }
    		}
    		if (maxIdx == 0) {
    		    continue;
    		}
    		for (int i = 0; i < maxIdx; i++) {
    		    if (arr[i] - '0' < j) {
    		        char tmp = arr[i];
    		        arr[i] = arr[maxIdx];
    		        arr[maxIdx] = tmp;
    		        hasFinish = true;
    		        break;
    		    }
    		}
    		if (hasFinish) {
    		    break;
    		}
		}
		System.out.println(arr);
   }
}

0