結果

問題 No.729 文字swap
ユーザー N.MatsumotoN.Matsumoto
提出日時 2019-09-21 21:26:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 76,636 KB
実行使用メモリ 57,556 KB
最終ジャッジ日時 2023-10-19 06:48:53
合計ジャッジ時間 4,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
57,552 KB
testcase_01 AC 133 ms
57,288 KB
testcase_02 AC 138 ms
57,316 KB
testcase_03 AC 144 ms
57,520 KB
testcase_04 AC 142 ms
57,356 KB
testcase_05 AC 144 ms
57,380 KB
testcase_06 AC 145 ms
57,376 KB
testcase_07 AC 139 ms
57,312 KB
testcase_08 AC 140 ms
57,364 KB
testcase_09 AC 139 ms
57,312 KB
testcase_10 AC 140 ms
57,556 KB
testcase_11 AC 139 ms
57,540 KB
testcase_12 AC 139 ms
57,292 KB
testcase_13 AC 142 ms
57,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] str = sc.next().split("");
        int from = sc.nextInt();
        int to = sc.nextInt();

        // 入れ替える文字を対比
        String fromStr = str[from];
        String toStr = str[to];

        // 文字入れ替え
        str[from] = toStr;
        str[to] = fromStr;

        String res = String.join("", str);
        System.out.print(res);
    }
}
0