結果

問題 No.238 Mr. K's Another Gift
ユーザー HIROPON87069639HIROPON87069639
提出日時 2016-02-22 21:47:52
言語 Python2
(2.7.18)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-09-22 13:06:23
合計ジャッジ時間 2,375 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

def kai(S):
    cnts = 0
    cntf = len(S)-1
    while cnts <= cntf :
        if S[cnts] != S[cntf]:
            return 0
        cnts += 1
        cntf -= 1
    return 1



S = list(raw_input())
if len(S) == 1:
    print "".join(S*2)
    exit()
if kai(S):
    n = len(S) / 2
    S.insert(n ,S[n])
    print "".join(S)
    exit()

cnts = 0
cntf = len(S)-1
while cnts <= cntf :
    if S[cnts] != S[cntf]:
        if S[cnts +1] == S[cntf]:
            S.insert(cntf+1, S[cnts])
            if kai(S):
                print "".join(S)
                exit()
            else:
                print "NA"
                exit()
        elif S[cnts] == S[cntf-1]:
            S.insert(cnts, S[cntf])
            if kai(S):
                print "".join(S)
                exit()
            else:
                print "NA"
                exit()
        else:
            print "NA"
            exit()
    cnts += 1
    cntf -= 1
0