1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ABC237 C問題(Python)

Last updated at Posted at 2022-02-06

#C - kasaka

解法の手順としては

  1. 文字列の前と後ろから見てaがいくつか連続するか見て、前の方が文字列aが少ない時、
      差分だけaを文字列の前に追加する
  2. 回文判定をする
      pythonの回文判定はこちらのページを参考にしました
      https://www.delftstack.com/ja/howto/python/python-palindrome/

留意点は二つ
一つ目、
同じ文字列を複数連続させるにはを使う
例えば、aがn回続く場合はa
n
二つ目、
while文のなかで、iとjが取れる範囲について注意する

S=list(input())
i=1
k1=0
p=0
l=0
while(S[-i]=='a'):
    l=l+1
    i=l+1
    if i>len(S):
      break
while(S[p]=='a'):
    p=p+1
    if p>len(S)-1:
      break
    
S=''.join(S)
n=l-p
if n>0:
  S='a'*n+S
if str(S) == str(S)[::-1] :
    print("Yes")
else:
    print("No")
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?