My code is passing for all test case but not in one and i can’t find my mistake…please help me…
here is the code
t=int(input())
while(t>0):
n=input()
i=0
while(n[i]==‘0’):
i+=1
n=n[i:]
k=len(n)
a=n[0]+‘9’(k-1)
if(n==a):
print(a)
else:
if(n[0]==‘1’):
i=1
while(i<k and n[i]==‘0’):
i+=1
if(i>=k-1):
print(n)
else:
a=n[:i+1]+‘9’(k-i-1)
if(n==a):
print(a)
else:
a=n[:i]+str(int(n[i])-1)+‘9’(k-i-1)
print(a)
else:
a=str(int(n[0])-1)+‘9’(k-1)
print(a)
t=t-1
Try the testcase:- 1000987
here is the answer
1
1000987
1000899
Your code gives wrong answer for n=100
Whats wrong with this code it is working correcly for upto 100000
in dev c++?
https://www.codechef.com/viewsolution/24386807
here is the answer for 100
1
100
100
which is wrong, answer should be 99 lol
answer for 100 is 99, his code gives 100, reverse 100 and you’ll get “1”
yeah just missed it …what a great mistake!!!
Actually your all answers are printing in reverse.
For 19 its printing 91.
and my reply was meant for you as his code gives gives correct answer for 1100
Thank you what a silly mistake i did
It’s giving 9901, which is incorrect…
Its correct 1100 = 1099 + 1
put 1099
1099 is correct actually
but 9901 is not
I am not talking about your code