Chewbacca and number

I am getting problem with leading zeroes.
please help.
(2 test cases passed)

#include
#include
using namespace std;
long long chew(long long x){
int i=0;
int num=0;
while(x!=0){
int t=x%10;
int a=9-t;
if(a<t){
num=num+apow(10,i);
}
else{
num=num+t
pow(10,i);
}
x=x/10;
i++;
}

return num;

}

int main() {
long long x;
cin>>x;
long long num=chew(x);
if(num<x){
cout<<num;
}
else if(num>x){

}
return 0;
}

yes
for input n = 9000
your code output is 0
but correct output is 9000

to handle this you have to make one more check
I have modified Your code check from below link

hi @shuja33
as i can see you have solved this question and got 100points also
so now kindly give your feedback asap, it hardly takes a min.

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.