結果

問題 No.39 桁の数字を入れ替え
ユーザー jp_stejp_ste
提出日時 2016-03-08 13:58:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 75,072 KB
実行使用メモリ 54,216 KB
最終ジャッジ日時 2024-04-10 05:21:19
合計ジャッジ時間 5,179 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
54,064 KB
testcase_01 AC 107 ms
52,936 KB
testcase_02 AC 121 ms
54,028 KB
testcase_03 AC 122 ms
54,124 KB
testcase_04 AC 121 ms
54,212 KB
testcase_05 AC 108 ms
52,940 KB
testcase_06 AC 120 ms
54,216 KB
testcase_07 AC 121 ms
54,072 KB
testcase_08 AC 119 ms
53,796 KB
testcase_09 AC 107 ms
52,932 KB
testcase_10 AC 121 ms
53,944 KB
testcase_11 AC 123 ms
53,884 KB
testcase_12 AC 121 ms
54,152 KB
testcase_13 AC 109 ms
53,072 KB
testcase_14 AC 118 ms
54,212 KB
testcase_15 AC 119 ms
54,160 KB
testcase_16 AC 122 ms
53,868 KB
testcase_17 AC 108 ms
53,088 KB
testcase_18 AC 123 ms
54,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            char tmp[] = scan.nextLine().toCharArray();
            int ans = Integer.parseInt(String.valueOf(tmp));
            
            for(int i=0; i<tmp.length-1; i++) {
                for(int j=i+1; j<tmp.length; j++) {
                    char left = tmp[i];
                    char right = tmp[j];
                    tmp[i] = right;
                    tmp[j] = left;
                    ans = Math.max(ans, Integer.parseInt(String.valueOf(tmp)));
                    tmp[i] = left;
                    tmp[j] = right;
                }
            }
            System.out.println(ans);
        }
    }
}
0