結果
問題 | No.39 桁の数字を入れ替え |
ユーザー | chiho_miyako |
提出日時 | 2015-04-18 21:56:37 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 125 ms / 5,000 ms |
コード長 | 1,024 bytes |
コンパイル時間 | 2,284 ms |
コンパイル使用メモリ | 78,008 KB |
実行使用メモリ | 54,584 KB |
最終ジャッジ日時 | 2024-04-10 04:50:07 |
合計ジャッジ時間 | 5,308 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 118 ms
54,096 KB |
testcase_01 | AC | 119 ms
54,216 KB |
testcase_02 | AC | 119 ms
53,816 KB |
testcase_03 | AC | 118 ms
54,584 KB |
testcase_04 | AC | 118 ms
54,124 KB |
testcase_05 | AC | 123 ms
54,456 KB |
testcase_06 | AC | 122 ms
54,336 KB |
testcase_07 | AC | 123 ms
54,120 KB |
testcase_08 | AC | 118 ms
53,960 KB |
testcase_09 | AC | 118 ms
54,028 KB |
testcase_10 | AC | 117 ms
53,980 KB |
testcase_11 | AC | 119 ms
53,888 KB |
testcase_12 | AC | 125 ms
54,248 KB |
testcase_13 | AC | 124 ms
54,272 KB |
testcase_14 | AC | 107 ms
53,044 KB |
testcase_15 | AC | 119 ms
53,988 KB |
testcase_16 | AC | 118 ms
54,040 KB |
testcase_17 | AC | 120 ms
54,160 KB |
testcase_18 | AC | 123 ms
54,400 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner koko = new Scanner(System.in); String n=koko.next(); int[] b = new int[n.length()]; int[] c = new int[n.length()]; for(int i=0; i<n.length(); i++){ b[i]=Character.getNumericValue(n.charAt(i)); c[i]=b[i]; } Arrays.sort(c); loop1: for(int i=0; i<n.length(); i++){ if(b[i]!=c[n.length()-1-i]){ for(int j=n.length()-1; j>i; j--){ if(b[j]==c[n.length()-1-i]){ int d = b[i]; b[i]=b[j]; b[j]=d; break loop1; } } } } char[] ans= new char[n.length()]; for(int i=0; i<n.length(); i++){ ans[i]=String.valueOf(b[i]).charAt(0); } String an = String.valueOf(ans); System.out.println(an); } }