結果

問題 No.39 桁の数字を入れ替え
ユーザー bambambambam
提出日時 2019-08-22 14:05:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 658 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 74,392 KB
実行使用メモリ 41,376 KB
最終ジャッジ日時 2024-04-20 13:27:23
合計ジャッジ時間 5,155 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
40,148 KB
testcase_01 AC 120 ms
41,252 KB
testcase_02 AC 117 ms
41,144 KB
testcase_03 AC 120 ms
41,364 KB
testcase_04 AC 120 ms
41,208 KB
testcase_05 AC 121 ms
41,104 KB
testcase_06 AC 108 ms
40,156 KB
testcase_07 AC 102 ms
40,080 KB
testcase_08 AC 107 ms
40,260 KB
testcase_09 AC 117 ms
41,376 KB
testcase_10 AC 103 ms
40,036 KB
testcase_11 AC 113 ms
40,952 KB
testcase_12 AC 106 ms
40,276 KB
testcase_13 AC 107 ms
40,104 KB
testcase_14 AC 118 ms
41,044 KB
testcase_15 AC 106 ms
40,224 KB
testcase_16 AC 104 ms
40,208 KB
testcase_17 AC 119 ms
41,328 KB
testcase_18 AC 103 ms
39,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char[] n = sc.next().toCharArray();
		char tmp;
		int idx;
		for (int i = 0; i < n.length - 1; i++) {
			tmp = '0';
			idx = 0;
			for (int j = n.length - 1; j > i; j--) {
				if (n[i] < n[j]) {
					if (tmp < n[j]) {
						tmp = n[j];
						idx = j;
					}
				}
			}
			if (tmp != '0') {
				n[idx] = n[i];
				n[i] = tmp;
				break;
			}
		}
		for (int i = 0; i < n.length; i++) {
			sb.append(n[i]);
		}
		System.out.println(sb);
	}
}
0