Regarding a program

I was doing a problem in assignment section “Chebecca and number”
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn’t good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t.

Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn’t start with a zero.

Input Format
The first line contains a single integer x (1 ≤ x ≤ 10^18) — the number that Luke Skywalker gave to Chewbacca.
But it is giving me time limit error.
How can I optimize my code.https://ide.codingblocks.com/s/440734

Hello @sarthak_singhal


check this.

@sarthak_singhal this question can also be done using character array:
so for your understanding i am giving you that code as well.

I have doubt in these lines https://ide.codingblocks.com/s/441472 I have commented on the line.

@sarthak_singhal when the digit is extracted as a character then they are in their ascii value.
like suppose we have extracted the character 4 then its ascii value will be 52.
and if we will subtract the ascii value of 0i.e 48 from it then the resulatant value will be the value which we have extracted.

and just like this in the second line which you have not understand after manipulating number when we want to store it in the character format then we will add the ascii value of 0 i.e 48 lets suppose if the integer is 4 and if we will add 48 in it then the ascii value of 52 is we have is 4 as a character.

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.