Chewbacca and Number

#include<bits/stdc++.h>
using namespace std;
int main() {
long long int n,num=0,num1=0;
cin>>n;
int rem;
while(n>0){
rem=n%10;
if(9-rem>0){
num=num10+min(rem,9-rem);
}
else{
num=num
10+rem;
}
n=n/10;
}
while(num>0){
rem=num%10;
num1=num1*10+rem;
num=num/10;
}
cout<<num1;
return 0;
}

I don’t know why this code is giving 80/100.
Works fine on the Hackerrank challenge probelm.

Hey @tgoel5884
for 99
output should be 90
Try to debug this on ur own now

Let me know if u need help :slight_smile:

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.

1 Like