結果

問題 No.39 桁の数字を入れ替え
ユーザー tenten
提出日時 2020-11-17 08:57:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 691 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 73,984 KB
実行使用メモリ 41,416 KB
最終ジャッジ日時 2024-07-23 01:55:31
合計ジャッジ時間 5,436 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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