結果

問題 No.238 Mr. K's Another Gift
ユーザー 37zigen37zigen
提出日時 2020-03-31 00:33:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 78,740 KB
実行使用メモリ 61,032 KB
最終ジャッジ日時 2023-09-05 12:35:43
合計ジャッジ時間 16,023 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 190 ms
57,328 KB
testcase_01 AC 195 ms
57,236 KB
testcase_02 AC 194 ms
57,060 KB
testcase_03 AC 197 ms
57,128 KB
testcase_04 AC 211 ms
57,520 KB
testcase_05 AC 309 ms
61,032 KB
testcase_06 AC 299 ms
60,296 KB
testcase_07 AC 309 ms
60,220 KB
testcase_08 AC 301 ms
59,956 KB
testcase_09 AC 298 ms
60,116 KB
testcase_10 AC 192 ms
55,524 KB
testcase_11 AC 195 ms
57,272 KB
testcase_12 AC 194 ms
57,384 KB
testcase_13 AC 207 ms
57,224 KB
testcase_14 AC 267 ms
59,780 KB
testcase_15 AC 305 ms
59,880 KB
testcase_16 AC 309 ms
60,420 KB
testcase_17 AC 308 ms
60,292 KB
testcase_18 AC 306 ms
60,232 KB
testcase_19 AC 294 ms
60,108 KB
testcase_20 AC 194 ms
57,244 KB
testcase_21 AC 198 ms
56,948 KB
testcase_22 AC 196 ms
57,092 KB
testcase_23 AC 196 ms
57,332 KB
testcase_24 AC 207 ms
57,776 KB
testcase_25 AC 212 ms
57,216 KB
testcase_26 AC 301 ms
60,124 KB
testcase_27 AC 310 ms
60,064 KB
testcase_28 AC 297 ms
60,120 KB
testcase_29 AC 310 ms
59,852 KB
testcase_30 AC 194 ms
56,936 KB
testcase_31 AC 190 ms
57,456 KB
testcase_32 AC 191 ms
57,132 KB
testcase_33 AC 211 ms
57,288 KB
testcase_34 AC 286 ms
60,896 KB
testcase_35 AC 304 ms
60,628 KB
testcase_36 AC 292 ms
60,100 KB
testcase_37 AC 304 ms
59,980 KB
testcase_38 AC 306 ms
60,904 KB
testcase_39 AC 306 ms
60,560 KB
testcase_40 AC 194 ms
56,868 KB
testcase_41 AC 198 ms
57,108 KB
testcase_42 AC 196 ms
57,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;


class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	boolean palindrome(String str) {
		char[] cs=str.toCharArray();
		int s=0;
		int t=cs.length-1;
		boolean ret=true;
		while(s<=t) {
			ret&=cs[s++]==cs[t--];
		}
		return ret;
	}
	
	
	
	void run() {
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		char[] cs=str.toCharArray();
		int n=cs.length;
		int s=0;int t=n-1;
		while(s<t&&cs[s]==cs[t]) {
			++s;--t;
		}
		String str1=str.substring(0,n/2)+"a"+str.substring(n/2,n);
		String str2=str.substring(0,s)+str.charAt(t)+str.substring(s,n);
		String str3=str.substring(0,t+1)+str.charAt(s)+str.substring(t+1,n);
		if(palindrome(str1)) {
			System.out.println(str1);
		}else if(palindrome(str2)) {
			System.out.println(str2);
		}else if(palindrome(str3)) {
			System.out.println(str3);
		}else {
			System.out.println("NA");
		}
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

0