結果

問題 No.1020 Reverse
ユーザー joybeeeejoybeeee
提出日時 2020-05-13 23:26:27
言語 Java19
(openjdk 21)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 467 bytes
コンパイル時間 2,537 ms
コンパイル使用メモリ 74,032 KB
実行使用メモリ 58,844 KB
最終ジャッジ日時 2023-10-12 17:10:38
合計ジャッジ時間 7,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,760 KB
testcase_01 AC 130 ms
55,604 KB
testcase_02 AC 130 ms
55,628 KB
testcase_03 AC 132 ms
55,720 KB
testcase_04 AC 129 ms
55,476 KB
testcase_05 AC 132 ms
55,656 KB
testcase_06 AC 132 ms
54,112 KB
testcase_07 AC 223 ms
56,864 KB
testcase_08 AC 224 ms
58,532 KB
testcase_09 AC 221 ms
58,216 KB
testcase_10 AC 230 ms
58,660 KB
testcase_11 AC 237 ms
58,288 KB
testcase_12 AC 234 ms
58,836 KB
testcase_13 AC 231 ms
58,844 KB
testcase_14 AC 233 ms
58,464 KB
testcase_15 AC 235 ms
58,388 KB
testcase_16 AC 235 ms
58,192 KB
testcase_17 AC 233 ms
58,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      String s = sc.next();
      String str1 = s.substring(0, k-1);
      String str2 = s.substring(k-1, n);
      if((n - k) % 2 == 0) {
        StringBuilder sb = new StringBuilder(str1);
        str1 = sb.reverse().toString();
      }
      System.out.println(str2 + str1);
  }
}
0