結果

問題 No.39 桁の数字を入れ替え
ユーザー shinshin
提出日時 2022-05-31 19:27:15
言語 Java
(openjdk 23)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 998 bytes
コンパイル時間 4,136 ms
コンパイル使用メモリ 79,856 KB
実行使用メモリ 52,356 KB
最終ジャッジ日時 2024-09-21 01:24:41
合計ジャッジ時間 6,154 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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