結果

問題 No.238 Mr. K's Another Gift
ユーザー tentententen
提出日時 2021-01-20 18:06:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 4,842 ms
コンパイル使用メモリ 73,444 KB
実行使用メモリ 56,868 KB
最終ジャッジ日時 2023-08-24 21:53:11
合計ジャッジ時間 11,841 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
56,168 KB
testcase_01 AC 118 ms
56,032 KB
testcase_02 AC 119 ms
55,940 KB
testcase_03 AC 122 ms
55,860 KB
testcase_04 AC 136 ms
55,616 KB
testcase_05 AC 207 ms
56,480 KB
testcase_06 AC 198 ms
56,276 KB
testcase_07 AC 199 ms
56,820 KB
testcase_08 AC 199 ms
56,380 KB
testcase_09 AC 201 ms
56,684 KB
testcase_10 AC 116 ms
55,552 KB
testcase_11 AC 116 ms
55,984 KB
testcase_12 AC 119 ms
55,736 KB
testcase_13 AC 128 ms
56,004 KB
testcase_14 AC 173 ms
56,372 KB
testcase_15 AC 191 ms
56,420 KB
testcase_16 AC 198 ms
56,672 KB
testcase_17 AC 190 ms
56,276 KB
testcase_18 AC 190 ms
56,424 KB
testcase_19 AC 186 ms
56,524 KB
testcase_20 AC 115 ms
55,544 KB
testcase_21 AC 115 ms
55,808 KB
testcase_22 AC 115 ms
55,728 KB
testcase_23 AC 120 ms
55,716 KB
testcase_24 AC 130 ms
56,020 KB
testcase_25 AC 135 ms
55,860 KB
testcase_26 AC 201 ms
56,136 KB
testcase_27 AC 208 ms
56,384 KB
testcase_28 AC 199 ms
56,108 KB
testcase_29 AC 208 ms
56,868 KB
testcase_30 AC 119 ms
55,732 KB
testcase_31 AC 117 ms
55,936 KB
testcase_32 AC 121 ms
56,080 KB
testcase_33 AC 134 ms
55,852 KB
testcase_34 AC 188 ms
56,288 KB
testcase_35 AC 201 ms
56,216 KB
testcase_36 AC 193 ms
56,616 KB
testcase_37 AC 200 ms
56,368 KB
testcase_38 AC 193 ms
56,392 KB
testcase_39 AC 192 ms
56,136 KB
testcase_40 AC 116 ms
55,672 KB
testcase_41 AC 118 ms
55,540 KB
testcase_42 AC 117 ms
55,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int left = 0;
		int right = s.length() - 1;
		int idx = -1;
		char c = ' ';
		while (left <= right) {
		    if (s.charAt(left) == s.charAt(right)) {
		        left++;
		        right--;
		        continue;
		    }
		    if (s.charAt(left + 1) == s.charAt(right)) {
		        if (idx >= 0) {
		            System.out.println("NA");
		            return;
		        }
		        idx = right + 1;
		        c = s.charAt(left);
		        left++;
		    } else if (s.charAt(left) == s.charAt(right - 1)) {
		        if (idx >= 0) {
		            System.out.println("NA");
		            return;
		        }
		        idx = left;
		        c = s.charAt(right);
		        right--;
		    } else {
		        System.out.println("NA");
		        return;
		    }
		}
		if (idx < 0) {
		    if (s.length() % 2 == 0) {
		        idx = s.length() / 2;
		        c = 'a';
		    } else {
		        idx = s.length() / 2;
		        c = s.charAt(idx);
		    }
		}
		s = new StringBuilder(s).insert(idx, c).toString();
		System.out.println(s);
	}
}
0