結果

問題 No.39 桁の数字を入れ替え
ユーザー tsunabittsunabit
提出日時 2019-09-05 11:31:41
言語 Java19
(openjdk 21)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 975 bytes
コンパイル時間 3,350 ms
コンパイル使用メモリ 75,776 KB
実行使用メモリ 56,392 KB
最終ジャッジ日時 2023-08-31 01:26:33
合計ジャッジ時間 6,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
56,300 KB
testcase_01 AC 101 ms
55,704 KB
testcase_02 AC 102 ms
56,036 KB
testcase_03 AC 99 ms
56,168 KB
testcase_04 AC 104 ms
56,392 KB
testcase_05 AC 101 ms
55,956 KB
testcase_06 AC 103 ms
56,008 KB
testcase_07 AC 104 ms
56,180 KB
testcase_08 AC 107 ms
55,716 KB
testcase_09 AC 105 ms
56,380 KB
testcase_10 AC 100 ms
55,816 KB
testcase_11 AC 103 ms
55,460 KB
testcase_12 AC 100 ms
56,188 KB
testcase_13 AC 106 ms
56,180 KB
testcase_14 AC 99 ms
55,832 KB
testcase_15 AC 102 ms
56,024 KB
testcase_16 AC 101 ms
55,916 KB
testcase_17 AC 99 ms
56,120 KB
testcase_18 AC 108 ms
56,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No39 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] n = sc.next().split("");
		int max = hoge(n);
		String[] temp = new String[n.length];
		for(int k = 0; k < n.length; k++) {
			temp[k] = n[k];
		}
		
		for(int i = 0; i < n.length; i++) {
			for(int j = i; j < n.length; j++) {
				String t = temp[i];
				temp[i] = temp[j];
				temp[j] = t;
				int v = hoge(temp);
//				System.out.println("[" + i + "]と[" + j + "] = " + v);
				if(max < v) max = v;
//				temp = n;
//				System.arraycopy(n, 0, temp, 0, n.length);
				for(int k = 0; k < n.length; k++) {
					temp[k] = n[k];
				}
//				System.out.println("temp初期化 = " + hoge(temp));
			}
		}
		System.out.println(max);
    }
	
	public static int hoge(String[] n) {
		String t = "";
		for(String v : n) {
			t += v;
		}
		int v = Integer.parseInt(t);
//		System.out.println(v);
		return v;
	}
}
0