結果

問題 No.238 Mr. K's Another Gift
ユーザー GrenacheGrenache
提出日時 2015-07-06 10:21:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 2,937 bytes
コンパイル時間 3,698 ms
コンパイル使用メモリ 75,340 KB
実行使用メモリ 52,940 KB
最終ジャッジ日時 2023-09-22 09:05:27
合計ジャッジ時間 8,282 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,424 KB
testcase_01 AC 40 ms
49,288 KB
testcase_02 AC 40 ms
49,228 KB
testcase_03 AC 43 ms
49,300 KB
testcase_04 AC 43 ms
49,300 KB
testcase_05 AC 99 ms
52,268 KB
testcase_06 AC 86 ms
52,044 KB
testcase_07 AC 101 ms
52,312 KB
testcase_08 AC 105 ms
52,668 KB
testcase_09 AC 106 ms
52,528 KB
testcase_10 AC 41 ms
49,496 KB
testcase_11 AC 40 ms
49,428 KB
testcase_12 AC 43 ms
49,292 KB
testcase_13 AC 41 ms
49,404 KB
testcase_14 AC 79 ms
51,304 KB
testcase_15 AC 93 ms
52,576 KB
testcase_16 AC 89 ms
52,648 KB
testcase_17 AC 85 ms
52,152 KB
testcase_18 AC 87 ms
51,956 KB
testcase_19 AC 88 ms
51,932 KB
testcase_20 AC 41 ms
49,628 KB
testcase_21 AC 42 ms
49,384 KB
testcase_22 AC 44 ms
49,308 KB
testcase_23 AC 41 ms
49,424 KB
testcase_24 AC 46 ms
49,348 KB
testcase_25 AC 51 ms
50,616 KB
testcase_26 AC 87 ms
51,864 KB
testcase_27 AC 105 ms
52,720 KB
testcase_28 AC 90 ms
52,132 KB
testcase_29 AC 104 ms
52,644 KB
testcase_30 AC 41 ms
49,136 KB
testcase_31 AC 40 ms
49,392 KB
testcase_32 AC 41 ms
49,308 KB
testcase_33 AC 46 ms
49,288 KB
testcase_34 AC 65 ms
52,088 KB
testcase_35 AC 92 ms
52,940 KB
testcase_36 AC 86 ms
51,996 KB
testcase_37 AC 84 ms
52,496 KB
testcase_38 AC 87 ms
52,188 KB
testcase_39 AC 83 ms
52,040 KB
testcase_40 AC 40 ms
49,400 KB
testcase_41 AC 40 ms
49,312 KB
testcase_42 AC 40 ms
49,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;


public class Main_yukicoder238_1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        char[] s = sc.next().toCharArray();
        int n = s.length;

        int offset;
        for (offset = 0; offset < n; offset++) {
    		if (s[offset] != s[n - 1 - offset]) {
    			break;
    		}
        }

        if (offset == n) {
        	StringBuilder ret = new StringBuilder();
        	int len = (n + 1) / 2;
        	ret.append(s, 0, len);
        	ret.append(s[len - 1]);
        	ret.append(s, len, n - len);
        	
        	pr.println(ret);
        } else {
        	StringBuilder ret = new StringBuilder();
        	ret.append(s);
        	ret.insert(offset, s[n - 1 - offset]);

        	boolean res = true;
            for (int i = 0; i < ret.length(); i++) {
            	if (ret.charAt(i) != ret.charAt(ret.length() - 1 - i)) {
            		res = false;
            		break;
            	}
            }
            
            if (res) {
            	pr.println(ret);
            } else {
            	ret = new StringBuilder();
            	ret.append(s);
            	ret.insert(n - offset, s[offset]);

            	res = true;
                for (int i = 0; i < ret.length(); i++) {
                	if (ret.charAt(i) != ret.charAt(ret.length() - 1 - i)) {
                		res = false;
                		break;
                	}
                }

                if (res) {
                	pr.println(ret);
                } else {
                	pr.println("NA");
                }
            }
        }

        pr.close();
        sc.close();
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;
		
		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		
		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}
		
		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0