結果

問題 No.238 Mr. K's Another Gift
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-22 18:49:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 77,724 KB
実行使用メモリ 54,764 KB
最終ジャッジ日時 2024-04-10 06:01:43
合計ジャッジ時間 10,376 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
53,464 KB
testcase_01 AC 105 ms
54,152 KB
testcase_02 AC 106 ms
52,708 KB
testcase_03 AC 106 ms
52,764 KB
testcase_04 AC 137 ms
54,232 KB
testcase_05 AC 188 ms
54,200 KB
testcase_06 AC 181 ms
54,764 KB
testcase_07 AC 198 ms
54,688 KB
testcase_08 AC 196 ms
54,476 KB
testcase_09 AC 187 ms
54,092 KB
testcase_10 AC 116 ms
53,852 KB
testcase_11 AC 110 ms
53,952 KB
testcase_12 AC 115 ms
54,108 KB
testcase_13 AC 125 ms
54,176 KB
testcase_14 AC 175 ms
54,176 KB
testcase_15 AC 177 ms
54,328 KB
testcase_16 AC 199 ms
54,536 KB
testcase_17 AC 169 ms
54,248 KB
testcase_18 AC 185 ms
54,096 KB
testcase_19 AC 182 ms
54,420 KB
testcase_20 AC 110 ms
54,120 KB
testcase_21 AC 119 ms
54,356 KB
testcase_22 AC 111 ms
54,256 KB
testcase_23 AC 122 ms
53,996 KB
testcase_24 AC 139 ms
53,836 KB
testcase_25 AC 130 ms
52,808 KB
testcase_26 AC 189 ms
54,360 KB
testcase_27 AC 194 ms
54,420 KB
testcase_28 AC 196 ms
54,176 KB
testcase_29 AC 206 ms
54,216 KB
testcase_30 AC 117 ms
53,908 KB
testcase_31 AC 103 ms
52,992 KB
testcase_32 AC 105 ms
52,940 KB
testcase_33 AC 132 ms
53,840 KB
testcase_34 AC 186 ms
54,424 KB
testcase_35 AC 198 ms
54,432 KB
testcase_36 AC 180 ms
54,432 KB
testcase_37 AC 190 ms
54,392 KB
testcase_38 AC 176 ms
54,368 KB
testcase_39 AC 177 ms
54,608 KB
testcase_40 AC 107 ms
52,712 KB
testcase_41 AC 116 ms
54,216 KB
testcase_42 AC 121 ms
54,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String s = sc.next();
		int a = 0;
		int b = 0;

		boolean F = true;
		for (int i=0; i<s.length()/2; i++) {
			if (s.charAt(i)!=s.charAt(s.length()-i-1)) {
				a = i;
				b = s.length()-i-1;
				F = false;;
				break;
			}
		}

		if (F==true) {
			StringBuilder sb = new StringBuilder(s);
			sb.insert(sb.length()/2,sb.charAt(sb.length()/2));
			System.out.println(sb);
		}
		else {
			StringBuilder sb1 = new StringBuilder(s);
			sb1.insert(a,s.charAt(b));
			StringBuilder sb2 = new StringBuilder(s);
			sb2.insert(b+1,s.charAt(a));
			if (IsPalindrome(sb1)) {System.out.println(sb1);}
			else if (IsPalindrome(sb2)) {System.out.println(sb2);}
			else {System.out.println("NA");}
		}
	}

	static boolean IsPalindrome (StringBuilder sb) {
		for (int i=0; i<sb.length()/2; i++) {
			if (sb.charAt(i)!=sb.charAt(sb.length()-i-1)) {
				return false;
			}
		}
		return true;
	}
}
0