Chewbacca Number Problem

What could I have missed?
#include
using namespace std;
int main() {

int x,count,z;
count = 1;
cin>>x;
int y=x;
while ((x/10)!=0){
	count++;
	x = x/10;
}
z = 0;
int arr[count];

for (int i=0; i<count; i++){
	arr[count-i-1] = y%10;
	y = y/10;
}

for (int j=0; j<count; j++){
	while (arr[j]==9){
		arr[j] = 9-arr[j];
	}
	if (arr[j]>=5){
		arr[j] = 9-arr[j];
	}
	
}
int f = 1;
for (int i=0; i<count; i++){
	z = z+(arr[count-i-1]*f);
	f = f*10;
}

cout<<z;
return 0;

}

@Chirag-Jain-1414278322030453
hello chirag if first digit is 9 then u cannot change it to 0.
for example
if x=9888
then answer should be 9111

I changed the code to:

#include using namespace std; int main() { int x,count,z; count = 1; cin>>x; int y=x; while ((x/10)!=0){ count++; x = x/10; } z = 0; int arr[count]; for (int i=0; i<count; i++){ arr[count-i-1] = y%10; y = y/10; } if (count==1){ if (arr[0]==9){ arr[0] = 9; } else{ if (arr[0]>=5){ arr[0] = 9-arr[0]; } } } else{ for (int i=0; i<count; i++){ if (i==0){ if (arr[i]!=9 and arr[i]>4){ arr[i] = 9-arr[i]; } else if (arr[i]==9){ arr[i] = 9; } } else{ if (arr[i]>4){ arr[i] = 9-arr[i]; } } } } int f = 1; for (int i=0; i<count; i++){ z = z+(arr[count-i-1]f); f = f10; } cout<<z; return 0; }

But there are still test cases failures

Please save your code on ide.codingblocks.com and then share its link.

link for code : https://ide.codingblocks.com/s/195453

Check it now…Since the constraints are very large, you must use long long int

it still seems to not work after changing int to long long int. Link to code - https://ide.codingblocks.com/s/195872

Replace line 50 with long long int f = 1;

I found another approach
code:
#include<bits/stdc++.h>
using namespace std;

int main(){

string str;
cin >> str;
for(int i = 0; i < str.length(); i++){

    int a = str[i]-48;
    if(a>4){
        a = 9 - a;
    }
    if(!a && !i)continue;
    str[i] = a +'0';
}
cout << str << endl;

return 0;

}