結果

問題 No.39 桁の数字を入れ替え
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-18 15:52:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 531 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 74,772 KB
実行使用メモリ 41,784 KB
最終ジャッジ日時 2024-04-24 06:00:16
合計ジャッジ時間 5,563 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,312 KB
testcase_01 AC 131 ms
41,344 KB
testcase_02 AC 130 ms
41,244 KB
testcase_03 AC 132 ms
41,148 KB
testcase_04 AC 127 ms
41,472 KB
testcase_05 AC 127 ms
41,636 KB
testcase_06 AC 130 ms
41,084 KB
testcase_07 AC 130 ms
41,672 KB
testcase_08 AC 130 ms
41,628 KB
testcase_09 AC 130 ms
41,784 KB
testcase_10 AC 129 ms
41,448 KB
testcase_11 AC 128 ms
41,276 KB
testcase_12 AC 123 ms
40,600 KB
testcase_13 AC 129 ms
41,208 KB
testcase_14 AC 130 ms
41,628 KB
testcase_15 AC 128 ms
41,092 KB
testcase_16 AC 129 ms
41,224 KB
testcase_17 AC 130 ms
41,532 KB
testcase_18 AC 134 ms
41,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int n = s.length;
		int max = Integer.valueOf(String.valueOf(s));
		for(int i=0;i<n;i++) {
			for(int j=i+1;j<n;j++) {
				swap(s, i, j);
				max = Math.max(max,Integer.valueOf(String.valueOf(s)));
				swap(s, i, j);
			}
		}
		System.out.println(max);
	}

	public static void swap(char[] a,int i,int j) {
		char temp = a[i];
		a[i] = a[j];
		a[j] = temp;
	}

}
0