My code for the given problem is
def nine(s,l):
for i in range(0,l):
if s[i]!=‘9’:
return 0
return 1
t=int(input())
while t!=0:
n=int(input())
s=str(n)
l=len(s)
if (nine(s,l)):
print(n+2)
else:
if l%2==0:
s1=s[:l//2-1]
if int(s1+s[l//2-1]+s[l//2-1]+s1[::-1])>n:
print(s1+s[l//2-1]+s[l//2-1]+s1[::-1])
else:
print(s1+str(int(s[l//2-1])+1)+str(int(s[l//2-1])+1)+s1[::-1])
else:
s1=s[:l//2]
if int(s1+s[l//2]+s1[::-1])>n:
print(s1+s[l//2]+s1[::-1])
else:
print(s1+str(int(s[l//2])+1)+s1[::-1])
t-=1
when i submit it to online judge it responds time limit exceeded but when i run it on ideone.com3 for any input it barely takes more than 0.09 sec.
please tell any mistake i have done.Thank you
created
last reply
- 3
replies
- 726
views
- 2
users
- 2
links