I dont know what is wrong with the code

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;

}

Hi, @gunjit27_94aa0450736b408e
your code gives wrong output for the test case : 10000000000 or above so just handle these cases.

Suggestion : You can take the input as a string and then things will be very easy for this question, like getting length of the number will be just using strlen() function and many more as with integer its becoming way complex.

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.