結果

問題 No.39 桁の数字を入れ替え
ユーザー YamaKasaYamaKasa
提出日時 2018-06-19 00:06:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 683 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 72,172 KB
実行使用メモリ 57,780 KB
最終ジャッジ日時 2023-09-13 06:59:30
合計ジャッジ時間 5,263 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,356 KB
testcase_01 AC 115 ms
55,456 KB
testcase_02 AC 116 ms
57,780 KB
testcase_03 AC 116 ms
56,072 KB
testcase_04 AC 115 ms
56,120 KB
testcase_05 AC 117 ms
55,968 KB
testcase_06 AC 119 ms
56,164 KB
testcase_07 AC 116 ms
56,180 KB
testcase_08 AC 119 ms
56,184 KB
testcase_09 AC 119 ms
54,328 KB
testcase_10 AC 116 ms
56,156 KB
testcase_11 AC 114 ms
56,388 KB
testcase_12 AC 117 ms
55,808 KB
testcase_13 AC 118 ms
56,444 KB
testcase_14 AC 116 ms
56,168 KB
testcase_15 AC 115 ms
56,060 KB
testcase_16 AC 114 ms
55,732 KB
testcase_17 AC 116 ms
56,044 KB
testcase_18 AC 116 ms
55,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		scan.close();
		String []ary = s.split("");
		int max = Integer.parseInt(s);
		for(int i = 0; i < ary.length; i++) {
			for(int j = i + 1; j < ary.length; j++) {
				int t = swap(ary, i, j);
				if(max < t) {
					max = t;
				}
			}
		}
		System.out.println(max);
	}
	public static int swap(String []A, int i, int j) {
		String []B = new String[A.length];
		for(int k = 0; k < A.length; k++) {
			B[k] = A[k];
		}
		String t = B[j];
		B[j] = B[i];
		B[i] = t;
		int a = Integer.parseInt(String.join("", B));
		return a;
	}
}
0