結果

問題 No.39 桁の数字を入れ替え
ユーザー atkrymatkrym
提出日時 2016-11-07 19:47:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 678 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 74,872 KB
実行使用メモリ 54,456 KB
最終ジャッジ日時 2024-04-10 05:39:06
合計ジャッジ時間 5,430 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,104 KB
testcase_01 AC 126 ms
54,128 KB
testcase_02 AC 126 ms
54,192 KB
testcase_03 AC 127 ms
54,004 KB
testcase_04 AC 126 ms
53,988 KB
testcase_05 AC 124 ms
54,108 KB
testcase_06 AC 124 ms
54,300 KB
testcase_07 AC 125 ms
54,248 KB
testcase_08 AC 127 ms
53,972 KB
testcase_09 AC 127 ms
53,988 KB
testcase_10 AC 125 ms
54,164 KB
testcase_11 AC 111 ms
52,708 KB
testcase_12 AC 125 ms
54,144 KB
testcase_13 AC 125 ms
54,108 KB
testcase_14 AC 126 ms
54,120 KB
testcase_15 AC 112 ms
53,016 KB
testcase_16 AC 125 ms
54,312 KB
testcase_17 AC 129 ms
53,984 KB
testcase_18 AC 127 ms
54,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String s = sc.next();
        int len = s.length();
        int max = Integer.valueOf(s);
        for (int i = 0;i < len;i++) {
            for (int j = i+1;j < len;j++) {
                max = Math.max(max, num(s,i,j));
            }
        }
        System.out.println(max);
    }
    
    private static int num(String s, int i, int j) {
        char[] ary = s.toCharArray();
        char tmp = ary[i];
        ary[i] = ary[j];
        ary[j] = tmp;
        return Integer.valueOf(new String(ary));
    }
}
0