I get the result as "Wrong answer" when I submit my code. But I get the wright answers while testing myself.
My code:
def check_even(digits):
temp=[]
for i in range(0,len(digits)):
if digits[i] & 1:
temp.append(1)
else:
temp.append(0)
return temp
T=int(input())
num=[]
digits=[]
for i in range(0,T):
num.append(input())
digits.append(list(map(int,str(num[i]))))
for element in range(0,len(digits)):
temp=check_even(digits[element])
td=int(num[element])
if 1 in temp:
#add
for i in range(1,len(temp)+1):
if temp[-i]==1:
td+=pow(10,i-1)-td%pow(10,i-1)
temp=check_even(list(map(int,str(td))))
add=td-int(num[element])
#sub
temp=check_even(digits[element])
td=int(num[element])
pos = temp.index(1)
count=len(str(td))-(pos+1)
td-=td%pow(10,count)
sub_num=('1'*(count-1))+'2'
td-=int(sub_num)
sub=int(num[element])-td
if add<sub:
print("Case #{}: {}".format(element+1,add))
else:
print("Case #{}: {}".format(element+1,sub))
else:
print("Case #{}: {}".format(element+1,0))
This code is the solution for google kickstart 2018 "Even digits" problem
Problem statement: Google kickstart 2018 Round A
Aucun commentaire:
Enregistrer un commentaire