結果

問題 No.2234 palindromer
ユーザー YutaYuta
提出日時 2023-03-14 14:15:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,896 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 11,928 KB
実行使用メモリ 10,092 KB
最終ジャッジ日時 2023-10-18 11:39:36
合計ジャッジ時間 1,237 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,092 KB
testcase_01 AC 29 ms
10,092 KB
testcase_02 AC 31 ms
10,092 KB
testcase_03 AC 33 ms
10,092 KB
testcase_04 AC 29 ms
10,092 KB
testcase_05 AC 29 ms
10,092 KB
testcase_06 AC 29 ms
10,092 KB
testcase_07 WA -
testcase_08 AC 28 ms
10,092 KB
testcase_09 AC 29 ms
10,092 KB
testcase_10 WA -
testcase_11 AC 29 ms
10,092 KB
testcase_12 AC 29 ms
10,092 KB
testcase_13 AC 28 ms
10,092 KB
testcase_14 WA -
testcase_15 AC 29 ms
10,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#完全に回文でない時に回文を作成する関数
def palindrome(sentence):
    if  sentence[-1] == sentence[-2]:
        sentence2 = sentence[::-1]
        sentence3 = sentence2[2:]
        new_sentence = sentence + sentence3
        print(new_sentence)



    else:
        sentence2 = sentence[::-1]
        sentence3 = sentence2[1:]
        new_sentence = sentence + sentence3
        print(new_sentence)


#与えられた文字列がもうすでに完全に回文か調べる関数
def check_palindrome(sentence):
    for i in range(len(sentence)):
        if sentence[i] == sentence[-(i + 1)]:
            pass


        else:
            break
    
    else:
        print(sentence)

#文字列が既に一部回文になりかかっているかどうか調べる関数

def check_palindrome2(sentence):
    for i in range(len(sentence) -2):

        if sentence[i] == sentence[i + 2] and sentence[i] == sentence[-(i + 1)]:
            break

        elif sentence[i] == sentence[i + 2]:

            if sentence[i - 1] == sentence[i + 3]:

                check_sentence = sentence[:i + 2]
                make_palindrome = check_sentence[::-1]
                make_palindrome2 = make_palindrome[1:]
                print(check_sentence + make_palindrome2)
                break

        


            else:
    
                pass

        elif sentence[i] == sentence[i+1]:
            if sentence[i-1] == sentence[i + 2]:
                check_sentence = sentence[:i + 2]
                make_palindrome = check_sentence[::-1]
                make_palindrome2 = make_palindrome[2:]
                print(check_sentence + make_palindrome2)

                break


        else:
            pass

    else:
        palindrome(sentence)


sentence = input("")

if len(sentence) >= 2:

    check_palindrome2(sentence)
    check_palindrome(sentence)

else:
    print(sentence)
0