結果

問題 No.39 桁の数字を入れ替え
ユーザー YamaKasa
提出日時 2018-06-19 00:06:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 683 bytes
コンパイル時間 2,386 ms
コンパイル使用メモリ 78,916 KB
実行使用メモリ 54,264 KB
最終ジャッジ日時 2024-06-30 17:07:28
合計ジャッジ時間 5,615 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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