結果

問題 No.39 桁の数字を入れ替え
ユーザー tentententen
提出日時 2020-11-17 08:57:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 691 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 72,348 KB
実行使用メモリ 57,672 KB
最終ジャッジ日時 2023-09-30 07:41:19
合計ジャッジ時間 5,441 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,572 KB
testcase_01 AC 120 ms
55,568 KB
testcase_02 AC 120 ms
55,548 KB
testcase_03 AC 119 ms
57,672 KB
testcase_04 AC 120 ms
55,312 KB
testcase_05 AC 120 ms
55,296 KB
testcase_06 AC 123 ms
55,648 KB
testcase_07 AC 121 ms
53,404 KB
testcase_08 AC 121 ms
55,888 KB
testcase_09 AC 120 ms
55,508 KB
testcase_10 AC 120 ms
55,788 KB
testcase_11 AC 121 ms
55,768 KB
testcase_12 AC 120 ms
55,448 KB
testcase_13 AC 120 ms
55,580 KB
testcase_14 AC 120 ms
55,920 KB
testcase_15 AC 120 ms
55,664 KB
testcase_16 AC 120 ms
55,756 KB
testcase_17 AC 120 ms
55,576 KB
testcase_18 AC 121 ms
55,424 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 i = 0; i < arr.length - 1; i++) {
            int max = arr[i];
            int idx = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (max <= arr[j]) {
                    idx = j;
                    max = arr[j];
                }
            }
            if (arr[i] < max) {
                char tmp = arr[idx];
                arr[idx] = arr[i];
                arr[i] = tmp;
                break;
            }
        }
        System.out.println(arr);
    }
}
0