Testcase 3 and 5 not passing

what is wrong in my code

hi Ayush
share ur code

#include<bits/stdc++.h>
using namespace std;
int main() {
long long int n,num=0,r;
cin>>n;
while(n>0)
{
r=n%10;
if(r>4)
r=9-r;
num=num*10+r;
n=n/10;
}
n=num;
num=0;
//Again inverting number
while(n>0)
{
r=n%10;

    num=num*10+r;
    n=n/10;
}
cout<<num<<endl;



return 0;

}

see the question say no leading zeros mean if number is 955 then ans is 944 and ur code didnot give it
also for 9999 ur code output 9 but ans should be 9000
just handel these 2 type

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.