Https://ide.codingblocks.com/s/479552

I am not able to understand where i am wrong in this question its not printing the answer

hello @architsuryavanshi

x will be zero in the last loop. thats why it is not printing anything.
u need to find the number of digit in the x and store it as size and then apply any logic.

btw string is good datastrucutr for this problem.

read a number as string (say s) .
if left most character is ‘9’

  • then leave the leftmost character as it is and for other characters simpl replace s[i] with min(s[i],‘9’-s[i])

else:

  • for each i replace s[i] with min(s[i],‘9’-s[i])

print s

#include<bits/stdc++.h>

using namespace std;

int main() {

    string n;

    cin>>n;

    int start=0;

    if(n[0]=='9')

       start=1;

    for(int i=start;i<n.length();i++){

            char c='9'-n[i]+'0';

            n[i]=min(n[i],c );

    }

    cout<<n;

    return 0;

}

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.