Chewbacca and number-Test case 3 and 5

this is my code and i cant get through test case 3 and 5
#include
using namespace std;
int main() {
long long int n=0,revers=0,rem=0;
cin>>n;
while(n!=0){
rem=n%10;
revers=revers*10+rem;
n/=10;
}
cout<<revers<<endl;
while(revers!=0){

rem=revers%10;      
if(rem>4){
	rem=9-rem;
}
n=n*10+rem;    
revers/=10;    
}
cout<<n;
return 0;

}