If you are using C you can take in the input in form of character by using getchar() in a while or for loop, then just use the ternary operator( ?: ) to print 5 if 0 comes and the number otherwise.
@shivam_gupta14 As the input size you are taking is 10^12 taking it in int data type will exceed its range…you can alternatively use long long int but that would also make the code complicated as you need to check for each digit.
The best way is to you can input the data in string or array of characters and just traverse the array using loop to check each element if it is equal to ‘0’(character) or not…