My code is showing case errors. Please help me in rectifying my code

Here is my code.

hi @sinchan1509_1a917d7b6cc3cbb9
Refer this code -->

Why is my code not working??

When u write int reverse, or int inverse, write long long int over there… it might work…

It is still showing two cases error one is 0 at last gets eliminated and other I don’t know how to eliminate them by modifying my code??

hi @sinchan1509_1a917d7b6cc3cbb9
consider the input as 1000…
expected o/p --> 1000
your o/p --> 1

hence u will have to change ur approach as this issue is being caused due to reversing the no… refer the code I sent above… explanation for the above code -->
The logic behind this Problem was pretty simple as we can invert any digit ( 9 - digit) but we need to invert only such digits that will eventually end up giving the smallest number possible.

So, we should invert only digits greater then or equal to 5 as after inverting them, the result gives us smallest number.

For e.g.,

9 - 5 = 4 viz, smaller than the original number that was 5.

9 - 8 = 1 viz, smaller than the original number that was 8.

but 9 - 1 = 8 viz, greater than the original number that was 1.

Important point to consider is, After inverting any digits their should not be trailing zeros that means, if their is 9 at the starting of the number then it must remain the same

Also input can be quite big so, u need to capture the number in long long int in c++

ok i got it i am working on the code you sent. I will let you know once I am completely done with the q

sure @sinchan1509_1a917d7b6cc3cbb9

if(rem==9 && (n/10)==0){ // do nothing }

Why is this code written what is the purpose is it for 0 in number??

Yes @sinchan1509_1a917d7b6cc3cbb9

ok thank you so much i didn’t copied your code as it is just made changes in my code after taking few things from yours

I got complete succes. thank you so much for helping me

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.