結果

問題 No.39 桁の数字を入れ替え
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-20 04:13:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 926 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 79,932 KB
実行使用メモリ 54,244 KB
最終ジャッジ日時 2024-04-10 05:39:33
合計ジャッジ時間 5,391 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
53,900 KB
testcase_01 AC 124 ms
54,040 KB
testcase_02 AC 113 ms
52,756 KB
testcase_03 AC 120 ms
54,036 KB
testcase_04 AC 123 ms
54,068 KB
testcase_05 AC 123 ms
54,092 KB
testcase_06 AC 123 ms
53,972 KB
testcase_07 AC 119 ms
54,092 KB
testcase_08 AC 124 ms
54,220 KB
testcase_09 AC 128 ms
54,172 KB
testcase_10 AC 124 ms
54,036 KB
testcase_11 AC 121 ms
54,152 KB
testcase_12 AC 117 ms
53,080 KB
testcase_13 AC 124 ms
54,136 KB
testcase_14 AC 121 ms
54,244 KB
testcase_15 AC 120 ms
54,096 KB
testcase_16 AC 122 ms
53,804 KB
testcase_17 AC 122 ms
54,144 KB
testcase_18 AC 124 ms
53,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        String r = rep(N);
        System.out.println(r);
    }
    static String rep(String S){
        String [] arr = S.split("");
        int max = 0;
        int c = 0;
        int z = arr.length;
        int [] t = new int [z];
        for(int i=0; i<z; i++){
            t[i]=Integer.parseInt(arr[i]);
            max=Math.max(max,t[i]);
            if(max==t[i]){
                c=i;
            }
        }
        if(max==t[0]){
            if(z==2){
                return S;
            }
            String x = arr[0]+rep(S.substring(1));
            return x;
        }else{
            String x = arr[c];
            arr[c]=arr[0];
            for(int i=1; i<z; i++){
                x=x+arr[i];
            }
            return x;
        }
    }
}
0