結果

問題 No.2234 palindromer
ユーザー YutaYuta
提出日時 2023-03-14 13:01:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,487 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 11,900 KB
実行使用メモリ 10,084 KB
最終ジャッジ日時 2023-10-18 11:37:30
合計ジャッジ時間 1,764 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,036 KB
testcase_01 AC 28 ms
10,036 KB
testcase_02 AC 27 ms
10,036 KB
testcase_03 AC 28 ms
10,036 KB
testcase_04 RE -
testcase_05 AC 29 ms
10,040 KB
testcase_06 AC 28 ms
10,040 KB
testcase_07 WA -
testcase_08 AC 29 ms
10,040 KB
testcase_09 AC 28 ms
10,040 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 29 ms
10,040 KB
testcase_13 AC 29 ms
10,040 KB
testcase_14 AC 29 ms
10,040 KB
testcase_15 AC 29 ms
10,040 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


        else:
            pass

    else:
        palindrome(sentence)


sentence = input("")

check_palindrome2(sentence)
check_palindrome(sentence)
0