Chewbacca and number

#include
using namespace std;
int main()
{
long long int n,num,ans=0,mult=1,rem;
cin>>n;
num=n;
while(num>0)
{
rem=num%10;
if(rem>=5&&rem!=9)
rem=9-rem;

    ans+=rem*mult;
    mult*=10;
    num/=10;

}
cout<<ans;
return 0;

}