結果

問題 No.39 桁の数字を入れ替え
ユーザー mobius_bkstmobius_bkst
提出日時 2015-05-03 15:14:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 1,003 bytes
コンパイル時間 3,436 ms
コンパイル使用メモリ 80,524 KB
実行使用メモリ 50,524 KB
最終ジャッジ日時 2024-04-10 04:50:50
合計ジャッジ時間 5,191 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
49,932 KB
testcase_01 AC 54 ms
50,448 KB
testcase_02 AC 54 ms
50,516 KB
testcase_03 AC 52 ms
50,332 KB
testcase_04 AC 52 ms
50,464 KB
testcase_05 AC 53 ms
50,520 KB
testcase_06 AC 56 ms
50,436 KB
testcase_07 AC 52 ms
50,524 KB
testcase_08 AC 54 ms
50,148 KB
testcase_09 AC 53 ms
50,348 KB
testcase_10 AC 52 ms
50,384 KB
testcase_11 AC 55 ms
50,392 KB
testcase_12 AC 53 ms
50,156 KB
testcase_13 AC 52 ms
50,448 KB
testcase_14 AC 53 ms
50,248 KB
testcase_15 AC 53 ms
50,176 KB
testcase_16 AC 52 ms
50,364 KB
testcase_17 AC 52 ms
50,484 KB
testcase_18 AC 53 ms
50,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class No039 {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            String S = br.readLine();
            int N = Integer.parseInt(S);
            int max = N;
            int Slength = S.length();
            char[] c;
            char tmp;
            int newN = 0;
            for (int j = 0; j < Slength; j++) {

                for (int i = j + 1; i < Slength; i++) {
                    c = S.toCharArray();
                    tmp = c[i];
                    c[i] = c[j];
                    c[j] = tmp;
                    newN = Integer.parseInt(String.copyValueOf(c));
                    max = Math.max(max, newN);
                }
            }
            System.out.println(max);
        } catch (Exception e) {
            System.err.println("Error:" + e.getMessage());
        }
    }

}
0