結果

問題 No.238 Mr. K's Another Gift
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-22 18:52:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 78,264 KB
実行使用メモリ 54,760 KB
最終ジャッジ日時 2024-04-10 06:07:26
合計ジャッジ時間 11,159 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
54,016 KB
testcase_01 AC 126 ms
54,392 KB
testcase_02 AC 130 ms
54,284 KB
testcase_03 AC 130 ms
54,112 KB
testcase_04 AC 142 ms
54,148 KB
testcase_05 AC 208 ms
54,348 KB
testcase_06 AC 201 ms
54,536 KB
testcase_07 AC 208 ms
54,528 KB
testcase_08 AC 205 ms
54,492 KB
testcase_09 AC 211 ms
54,684 KB
testcase_10 AC 126 ms
53,880 KB
testcase_11 AC 128 ms
54,252 KB
testcase_12 AC 131 ms
54,032 KB
testcase_13 AC 149 ms
54,148 KB
testcase_14 AC 196 ms
54,284 KB
testcase_15 AC 213 ms
54,408 KB
testcase_16 AC 200 ms
54,512 KB
testcase_17 AC 190 ms
54,384 KB
testcase_18 AC 192 ms
54,372 KB
testcase_19 AC 182 ms
54,112 KB
testcase_20 AC 128 ms
54,188 KB
testcase_21 AC 126 ms
53,840 KB
testcase_22 AC 126 ms
54,220 KB
testcase_23 AC 133 ms
54,292 KB
testcase_24 AC 141 ms
54,048 KB
testcase_25 AC 146 ms
54,208 KB
testcase_26 AC 209 ms
54,388 KB
testcase_27 AC 210 ms
54,760 KB
testcase_28 AC 201 ms
54,340 KB
testcase_29 AC 216 ms
54,500 KB
testcase_30 AC 129 ms
54,172 KB
testcase_31 AC 129 ms
54,004 KB
testcase_32 AC 130 ms
54,196 KB
testcase_33 AC 146 ms
53,940 KB
testcase_34 AC 196 ms
54,280 KB
testcase_35 AC 203 ms
54,236 KB
testcase_36 AC 192 ms
54,464 KB
testcase_37 AC 199 ms
54,408 KB
testcase_38 AC 197 ms
54,448 KB
testcase_39 AC 181 ms
54,640 KB
testcase_40 AC 128 ms
53,924 KB
testcase_41 AC 130 ms
54,344 KB
testcase_42 AC 126 ms
54,120 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;
		int n = s.length();
		boolean F = true;
		for (int i=0; i<n/2; i++) {
			if (s.charAt(i)!=s.charAt(n-i-1)) {
				a = i;
				b = n-i-1;
				F = false;;
				break;
			}
		}
		
		if (F==true) {
			StringBuilder sb = new StringBuilder(s);
			sb.insert(n/2,sb.charAt(n/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) {
		int n = sb.length();
		for (int i=0; i<n/2; i++) {
			if (sb.charAt(i)!=sb.charAt(n-i-1)) {
				return false;
			}
		}
		return true;
	}
}
0