結果

問題 No.39 桁の数字を入れ替え
ユーザー rn4rurn4ru
提出日時 2016-04-13 04:25:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 516 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 75,032 KB
実行使用メモリ 54,212 KB
最終ジャッジ日時 2024-04-10 05:22:15
合計ジャッジ時間 5,206 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
53,896 KB
testcase_01 AC 117 ms
54,084 KB
testcase_02 AC 120 ms
53,980 KB
testcase_03 AC 121 ms
54,052 KB
testcase_04 AC 119 ms
54,064 KB
testcase_05 AC 119 ms
53,876 KB
testcase_06 AC 108 ms
52,924 KB
testcase_07 AC 119 ms
53,940 KB
testcase_08 AC 117 ms
53,944 KB
testcase_09 AC 120 ms
54,032 KB
testcase_10 AC 108 ms
52,956 KB
testcase_11 AC 120 ms
53,756 KB
testcase_12 AC 118 ms
54,212 KB
testcase_13 AC 119 ms
54,128 KB
testcase_14 AC 122 ms
54,132 KB
testcase_15 AC 123 ms
54,108 KB
testcase_16 AC 119 ms
54,096 KB
testcase_17 AC 120 ms
53,856 KB
testcase_18 AC 122 ms
54,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		char[] c = scanner.next().toCharArray();

		for (int i = 0; i < c.length - 1; i++) {
			int max = -1;
			int index = 0;
			for (int j = i; j < c.length; j++) {
				if (max <= c[j]) {
					max = c[j];
					index = j;
				}
			}
			if (c[i] < max) {
				char temp = c[i];
				c[i] = c[index];
				c[index] = temp;
				break;
			}
		}

		System.out.println(String.valueOf(c));
	}

}
0