According to the question, the inverse of a number is 9-t so I am doing that and have made sure that if the first digit is 9 then it will not be inversed, and still, 2 test cases have failed. Can you look at my code and see what I am doing wrong?
Thank You
#include
using namespace std;
int len(int n){
int i,j,k;
i = 1;
j = 1;
while(i>0){
n = n/10;
if(n==0){
i--;
}
else{
j++;
}
}
return j;
}
int main(){
long long int n;
int op;
cin>>n;
op = 0;
if(n<=100000000000000000){
int i,j,k,l,nolen;
nolen = len(n);
j = 1;
for(i=1;i<=nolen;i++){
k = n%10;
l = 9-k;
if(i==nolen){
if(k==9){
op = op+k*j;
}
else{
if(k>l){
op = op + l*j;
}
else{
op = op + k*j;
}
}
}
else{
if(k>l){
op = op + l*j;
}
else{
op = op + k*j;
}
}
j = j*10;
n = n/10;
}
}
cout<<op<<endl;
return 0;
}