結果

問題 No.39 桁の数字を入れ替え
ユーザー kohaku_kohaku
提出日時 2016-11-20 04:13:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 926 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 80,236 KB
実行使用メモリ 41,632 KB
最終ジャッジ日時 2024-10-02 07:14:55
合計ジャッジ時間 5,581 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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