結果

問題 No.39 桁の数字を入れ替え
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-04-05 00:18:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 1,068 bytes
コンパイル時間 3,542 ms
コンパイル使用メモリ 78,664 KB
実行使用メモリ 54,348 KB
最終ジャッジ日時 2024-04-10 04:48:18
合計ジャッジ時間 6,835 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
54,212 KB
testcase_01 AC 131 ms
54,152 KB
testcase_02 AC 123 ms
54,140 KB
testcase_03 AC 121 ms
53,932 KB
testcase_04 AC 119 ms
54,120 KB
testcase_05 AC 118 ms
54,012 KB
testcase_06 AC 107 ms
52,860 KB
testcase_07 AC 123 ms
54,000 KB
testcase_08 AC 122 ms
53,864 KB
testcase_09 AC 121 ms
53,992 KB
testcase_10 AC 119 ms
54,068 KB
testcase_11 AC 121 ms
54,000 KB
testcase_12 AC 125 ms
54,116 KB
testcase_13 AC 107 ms
53,036 KB
testcase_14 AC 111 ms
53,008 KB
testcase_15 AC 120 ms
54,348 KB
testcase_16 AC 119 ms
52,940 KB
testcase_17 AC 109 ms
52,964 KB
testcase_18 AC 112 ms
52,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.39 桁の数字を入れ替え

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No39 {
    
    static final Scanner sc = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        int n = sc.nextInt();
        char[] cs = String.valueOf(n).toCharArray();
        int max = n;
        for (int i=0; i<cs.length; i++) {
            for (int j=i+1; j<cs.length; j++) {
                char t = cs[i]; cs[i] = cs[j]; cs[j] = t;
                max = max(max,Integer.parseInt(String.valueOf(cs)));
                t = cs[i]; cs[i] = cs[j]; cs[j] = t;
            }
        }
        out.println(max);
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        sc.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0