結果

問題 No.238 Mr. K's Another Gift
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-22 18:44:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 813 bytes
コンパイル時間 2,828 ms
コンパイル使用メモリ 77,652 KB
実行使用メモリ 54,952 KB
最終ジャッジ日時 2024-04-10 05:53:44
合計ジャッジ時間 11,520 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
53,764 KB
testcase_01 AC 119 ms
53,840 KB
testcase_02 AC 108 ms
52,952 KB
testcase_03 AC 112 ms
52,940 KB
testcase_04 WA -
testcase_05 AC 209 ms
54,368 KB
testcase_06 WA -
testcase_07 AC 219 ms
54,588 KB
testcase_08 AC 216 ms
54,688 KB
testcase_09 AC 223 ms
54,656 KB
testcase_10 AC 120 ms
54,156 KB
testcase_11 AC 121 ms
54,356 KB
testcase_12 AC 125 ms
54,352 KB
testcase_13 AC 142 ms
54,256 KB
testcase_14 AC 181 ms
54,468 KB
testcase_15 AC 214 ms
54,572 KB
testcase_16 AC 211 ms
54,580 KB
testcase_17 AC 189 ms
54,496 KB
testcase_18 AC 197 ms
54,320 KB
testcase_19 AC 190 ms
54,456 KB
testcase_20 AC 120 ms
53,884 KB
testcase_21 AC 119 ms
54,096 KB
testcase_22 WA -
testcase_23 AC 123 ms
54,264 KB
testcase_24 AC 146 ms
54,120 KB
testcase_25 AC 141 ms
54,168 KB
testcase_26 WA -
testcase_27 AC 210 ms
54,448 KB
testcase_28 AC 227 ms
54,416 KB
testcase_29 AC 220 ms
54,804 KB
testcase_30 AC 117 ms
54,160 KB
testcase_31 AC 121 ms
54,112 KB
testcase_32 AC 121 ms
53,864 KB
testcase_33 AC 150 ms
54,012 KB
testcase_34 AC 184 ms
54,724 KB
testcase_35 AC 200 ms
54,520 KB
testcase_36 AC 199 ms
54,508 KB
testcase_37 AC 199 ms
54,608 KB
testcase_38 AC 194 ms
54,628 KB
testcase_39 AC 192 ms
54,252 KB
testcase_40 AC 119 ms
54,128 KB
testcase_41 AC 120 ms
54,352 KB
testcase_42 AC 120 ms
54,096 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;
		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;
				break;
			}
		}
		
		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