結果

問題 No.39 桁の数字を入れ替え
ユーザー spaciaspacia
提出日時 2016-01-13 23:26:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 785 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 76,012 KB
実行使用メモリ 50,676 KB
最終ジャッジ日時 2024-04-10 05:18:11
合計ジャッジ時間 3,881 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
50,532 KB
testcase_01 AC 55 ms
50,676 KB
testcase_02 AC 53 ms
50,184 KB
testcase_03 AC 54 ms
50,008 KB
testcase_04 AC 54 ms
50,496 KB
testcase_05 AC 54 ms
50,464 KB
testcase_06 AC 54 ms
50,264 KB
testcase_07 AC 54 ms
50,036 KB
testcase_08 AC 54 ms
50,400 KB
testcase_09 AC 53 ms
50,512 KB
testcase_10 AC 53 ms
50,336 KB
testcase_11 AC 52 ms
50,480 KB
testcase_12 AC 53 ms
50,504 KB
testcase_13 AC 53 ms
50,516 KB
testcase_14 AC 53 ms
50,440 KB
testcase_15 AC 53 ms
50,488 KB
testcase_16 AC 54 ms
50,548 KB
testcase_17 AC 53 ms
50,428 KB
testcase_18 AC 53 ms
50,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main {
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static void solve (int n) {
		char[] c = (n + "").toCharArray();
		for (int i = 0; i < c.length - 1; i++) {
			int d = c[i] - '0';
			int max = d , maxI = -1;
			for (int j = c.length - 1; j > i; j--) {
				int e = c[j] - '0';
				if (max < e) {
					max = e;
					maxI = j;
				}
			}
			if (maxI != -1) {
				char tmp = c[i];
				c[i] = c[maxI];
				c[maxI] = tmp;
				break;
			}
		}
		
		for (char d : c)
			System.out.print(d);
		out("");
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		solve(n);
	}
}
0