I solved this q but i got some other method too..but it is failing test case 2nd..why?

#include
using namespace std;
int check(int n){
int num = 0;
int i = 1;
int num1;
if (n==0){
return 5;
}
while(n!=0){
int digit = n%10;
if(digit == 0){
digit = 5;
}
num = num + i*digit;
i *= 10;
n /= 10;
}
return num;
}

int main() {
int n;
cin>>n;
cout<<check(n);
return 0;
}

your code is correct and it pass all testcases…

check once the same code :

if you have further doubt, then feel free to ask

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.