結果

問題 No.39 桁の数字を入れ替え
ユーザー tentententen
提出日時 2022-10-13 14:01:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 1,486 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 74,120 KB
実行使用メモリ 49,820 KB
最終ジャッジ日時 2023-09-08 19:06:20
合計ジャッジ時間 3,856 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,396 KB
testcase_01 AC 43 ms
49,308 KB
testcase_02 AC 43 ms
49,348 KB
testcase_03 AC 43 ms
49,248 KB
testcase_04 AC 43 ms
49,232 KB
testcase_05 AC 43 ms
49,252 KB
testcase_06 AC 42 ms
49,080 KB
testcase_07 AC 43 ms
49,092 KB
testcase_08 AC 42 ms
49,252 KB
testcase_09 AC 42 ms
49,080 KB
testcase_10 AC 43 ms
49,456 KB
testcase_11 AC 43 ms
49,420 KB
testcase_12 AC 43 ms
49,168 KB
testcase_13 AC 43 ms
49,820 KB
testcase_14 AC 43 ms
47,648 KB
testcase_15 AC 43 ms
49,360 KB
testcase_16 AC 43 ms
49,292 KB
testcase_17 AC 42 ms
49,192 KB
testcase_18 AC 43 ms
49,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] values = sc.next().toCharArray();
        for (int i = 0; i < values.length - 1; i++) {
            char max = '0';
            int idx = 0;
            for (int j = i + 1; j < values.length; j++) {
                if (max <= values[j]) {
                    max = values[j];
                    idx = j;
                }
            }
            if (values[i] < max) {
                char tmp = values[idx];
                values[idx] = values[i];
                values[i] = tmp;
                break;
            }
        }
        System.out.println(values);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0