結果
問題 | No.2234 palindromer |
ユーザー |
|
提出日時 | 2023-03-14 12:25:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,374 bytes |
コンパイル時間 | 205 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-09-18 07:59:02 |
合計ジャッジ時間 | 1,526 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 WA * 5 RE * 1 |
ソースコード
#完全に回文でない時に回文を作成する関数 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]: check_sentence = sentence[:i + 2] make_palindrome = check_sentence[::-1] make_palindrome2 = make_palindrome[1:] print(check_sentence + make_palindrome2) break else: pass else: palindrome(sentence) sentence = input("") check_palindrome2(sentence) check_palindrome(sentence)