Chewbacca and Number

Why it is not passing all test cases?
#include
#include<bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin>>n;
stack s;
while(n!=0)
{
long long int r=n%10;
if(9-r<r)
{
s.push(9-r);
}
else
{
s.push®;
}
n=n/10;
}
while(!s.empty())
{
if(s.top()!=0)
{
break;
}
s.pop();
}
while (!s.empty())
{
cout << s.top();
s.pop();
}
return 0;
}

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


this is the link to the problem it is not passing two test cases

Consider a case:
9

Your O/p
0

Expected o/p
9

1 Like

thanks it passed all test cases

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.