結果

問題 No.39 桁の数字を入れ替え
ユーザー shinshin
提出日時 2022-05-31 19:27:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 998 bytes
コンパイル時間 4,154 ms
コンパイル使用メモリ 80,376 KB
実行使用メモリ 53,824 KB
最終ジャッジ日時 2023-10-21 00:43:53
合計ジャッジ時間 5,959 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
53,820 KB
testcase_01 AC 59 ms
53,816 KB
testcase_02 AC 60 ms
53,816 KB
testcase_03 AC 59 ms
53,808 KB
testcase_04 AC 59 ms
53,820 KB
testcase_05 AC 59 ms
53,820 KB
testcase_06 AC 60 ms
53,824 KB
testcase_07 AC 58 ms
53,820 KB
testcase_08 AC 59 ms
52,780 KB
testcase_09 AC 61 ms
52,712 KB
testcase_10 AC 59 ms
53,812 KB
testcase_11 AC 60 ms
53,820 KB
testcase_12 AC 59 ms
53,812 KB
testcase_13 AC 59 ms
53,808 KB
testcase_14 AC 59 ms
53,804 KB
testcase_15 AC 59 ms
53,816 KB
testcase_16 AC 59 ms
53,808 KB
testcase_17 AC 58 ms
53,812 KB
testcase_18 AC 58 ms
53,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class No39 {

	public static void main(String[] args) throws IOException{
		//桁の数字を入れ替え
		String str = readStr()[0] , s;
		String[] N = str.split("") , clone;
		int max = Integer.parseInt(str);
		
		for(int i = 0;i < N.length;i++) {
			for(int j = i + 1;j < N.length;j++) {
				clone = N.clone();
				str = "";
				s = clone[j];
				clone[j] = clone[i];
				clone[i] = s;
				for(String c : clone) {
					str += c;
				}
				max = Math.max(max, Integer.parseInt(str));
			}
		}
		
		System.out.println(max);

	}
	
	public static String[] readStr() throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> list = new ArrayList<>();

		do {
			list.add(br.readLine());
		}while(br.ready());

		br.close();

		String[] text = new String[list.size()];
		list.toArray(text);

		return text;

	}

}
0