結果
問題 |
No.39 桁の数字を入れ替え
|
ユーザー |
![]() |
提出日時 | 2016-01-13 23:26:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 63 ms / 5,000 ms |
コード長 | 785 bytes |
コンパイル時間 | 2,807 ms |
コンパイル使用メモリ | 76,156 KB |
実行使用メモリ | 37,608 KB |
最終ジャッジ日時 | 2024-10-02 06:50:35 |
合計ジャッジ時間 | 4,595 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
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); } }