Want to know what is wrong in this code and explain how it can be corrected

#include
using namespace std;
int main() {
long long int x;
cin>>x;
long long int v=x;
long long int sum= 0;
long long int mul= 1;
while(v!=0){
long long int rem =v%10;
v=v/10;
if(rem>=5){
rem=9-rem;
sum=sum+remmul;
}
else if(rem==9 && v==0){
sum=sum+9
mul;
}
else{
sum=sum+remmul;
}
mul=mul
10;
}
cout<<sum;
}

hi @jharshitjindal_4da85e4d0b87909f
if digit is >5 flip that digit otherwise don’t flip
also check some corner cases
a) first digit should not be zero so if first digit is 9 then it should remain unchanged
b) if number is 0 only then output should be 9, not 0.

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++ and long in java.

for implementation difficulties refer https://ide.codingblocks.com/s/658154

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.