結果

問題 No.238 Mr. K's Another Gift
ユーザー GrenacheGrenache
提出日時 2015-07-06 10:18:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,917 bytes
コンパイル時間 3,587 ms
コンパイル使用メモリ 75,824 KB
実行使用メモリ 53,756 KB
最終ジャッジ日時 2023-09-22 09:05:02
合計ジャッジ時間 9,603 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,276 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 45 ms
49,572 KB
testcase_05 AC 96 ms
52,748 KB
testcase_06 AC 91 ms
52,020 KB
testcase_07 AC 100 ms
52,172 KB
testcase_08 AC 106 ms
52,528 KB
testcase_09 AC 110 ms
50,796 KB
testcase_10 AC 44 ms
49,376 KB
testcase_11 AC 42 ms
49,424 KB
testcase_12 AC 44 ms
49,744 KB
testcase_13 AC 44 ms
49,240 KB
testcase_14 AC 89 ms
53,756 KB
testcase_15 AC 90 ms
52,480 KB
testcase_16 AC 86 ms
52,576 KB
testcase_17 AC 84 ms
51,984 KB
testcase_18 AC 87 ms
51,992 KB
testcase_19 AC 80 ms
51,864 KB
testcase_20 WA -
testcase_21 AC 42 ms
49,296 KB
testcase_22 AC 42 ms
49,428 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 90 ms
52,924 KB
testcase_27 AC 110 ms
52,576 KB
testcase_28 AC 90 ms
52,096 KB
testcase_29 AC 108 ms
52,540 KB
testcase_30 AC 43 ms
49,600 KB
testcase_31 AC 42 ms
49,264 KB
testcase_32 AC 44 ms
49,588 KB
testcase_33 AC 50 ms
49,800 KB
testcase_34 AC 84 ms
51,996 KB
testcase_35 AC 98 ms
52,828 KB
testcase_36 AC 94 ms
52,288 KB
testcase_37 AC 95 ms
52,088 KB
testcase_38 AC 87 ms
51,832 KB
testcase_39 AC 84 ms
51,988 KB
testcase_40 AC 43 ms
49,296 KB
testcase_41 AC 43 ms
49,136 KB
testcase_42 AC 43 ms
49,804 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