結果

問題 No.39 桁の数字を入れ替え
ユーザー htensaihtensai
提出日時 2019-12-07 09:54:33
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 557 bytes
コンパイル時間 3,601 ms
コンパイル使用メモリ 72,072 KB
実行使用メモリ 56,160 KB
最終ジャッジ日時 2023-08-26 02:41:14
合計ジャッジ時間 5,160 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,732 KB
testcase_01 AC 116 ms
55,912 KB
testcase_02 AC 116 ms
55,572 KB
testcase_03 AC 117 ms
55,984 KB
testcase_04 AC 117 ms
55,876 KB
testcase_05 AC 117 ms
55,640 KB
testcase_06 AC 116 ms
56,160 KB
testcase_07 AC 117 ms
53,688 KB
testcase_08 AC 116 ms
56,032 KB
testcase_09 AC 115 ms
55,808 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 116 ms
55,716 KB
testcase_15 AC 117 ms
55,624 KB
testcase_16 AC 117 ms
55,944 KB
testcase_17 AC 116 ms
55,908 KB
testcase_18 AC 116 ms
55,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int max = 0;
		int maxIdx = 0;
		for (int i = 0; i < arr.length; i++) {
		    if (max <= arr[i] - '0') {
		        max = arr[i] - '0';
		        maxIdx = i;
		    }
		}
		for (int i = 0; i < maxIdx; i++) {
		    if (arr[i] - '0' < max) {
		        char tmp = arr[i];
		        arr[i] = arr[maxIdx];
		        arr[maxIdx] = tmp;
		        break;
		    }
		}
		System.out.println(arr);
   }
}

0