i am not getting why is my code failing few of the test cases. please help me!!
#include
using namespace std;
int main()
{
int n;
cin>>n;
int check=0;
int recheck=0;
int alt;
alt =n;
while(alt>0)
{
check++;
alt=alt/10;
}
alt = n;
int arr[check+1000];
for(int i=check-1; i>=0; i--)
{
arr[i]=(alt%10);
alt = alt/10;
}
for(int i=0; i<check; i++)
{
if((9-arr[i])<arr[i])
{
arr[i]=9-arr[i];
}
}
for(int i=0; i<check; i++)
{
if(arr[i]==0)
{
recheck++;
}
else
{
i =(check-1);
}
}
for(int i=0; i<recheck; i++)
{
arr[i] = (9-arr[i]);
}
for(int i=0; i<check; i++)
{
cout<<arr[i];
}
return 0;
}