ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1354. Palindrome. Again Palindrome

WA #10
Posted by Ivan 1 Feb 2019 13:05
I really don't know whats wrong with this
May somebody tell me test case 10?

here are some code

def find_palindrome(string): #findes palindrom that include string[0]
palindrom=string[0]
len_string = int(len(string)/2-1)
lalak = len(string)-1
for i in range(len_string,-1,-1):
j=0
while True:
if i-j>0 :
if string[i-j]==string[i+j]:
j+=1
else:
break
elif i-j==0:
if  string[i-j]==string[i+j]:
if len(string[0:i+j+1]) > len(palindrom):
palindrom = string[0:i+j+1]
break
j = 0
while True:
if lalak+j < len(string)-1:
if string[lalak-j]==string[lalak+j]:
j+=1
else:
break
elif lalak+j==len(string)-1:
if  string[lalak-j]==string[lalak+j]:
if len(string[lalak-j:len(string)]) >= len(palindrom):
palindrom = string[lalak-j:len(string)]
break
lalak-=1
return palindrom

def find_palindrome_2(string):
palindrom=string[0]
if len(string)%2==0:
len_string = int(len(string)/2-2)
if len(string)%2==1:
len_string = int(len(string)/2-1)
lalak = len(string)-1
for i in range(len_string,-1,-1):
j=0
while True:
if i-j>0 :
if string[i-j]==string[i+j+1]:
j+=1
else:
break
elif i-j==0:
if  string[i-j]==string[i+j+1]:
if len(string[0:i+j+2]) > len(palindrom):
palindrom = string[0:i+j+2]
break
j = 0
while True:
if lalak+j < len(string)-1:
if string[lalak-j-1]==string[lalak+j]:
j+=1
else:
break
elif lalak+j==len(string)-1:
if  string[lalak-j-1]==string[lalak+j]:
if len(string[lalak-j-1:len(string)]) >= len(palindrom):
palindrom = string[lalak-j-1:len(string)]
break
lalak-=1
return palindrom

str_1=input()
if len(str_1)==1:
print(str_1+str_1)
else:
res = [find_palindrome_2(str_1),find_palindrome(str_1)]
if len(res[0])==len(res[1]):
res_2=res[1]
else:
res_2=max(res, key=len)
if  res_2==str_1[len(str_1)-len(res_2):len(str_1)]:
for i in range(len(str_1)-len(res_2)-1,-1,-1):
str_1=str_1+str_1[i]
elif res_2==str_1[0:len(res_2)]:
for i in str_1[len(res_2):]:
str_1=i+str_1
print(str_1)