#K11291. Product of Non-Zero Digits
Product of Non-Zero Digits
Product of Non-Zero Digits
Given a string consisting of digits, compute the product of all non-zero digits. If the input string is empty or contains only zeros, output 0. More formally, if the input string is \(S\) and its characters are \(S_1, S_2, \dots, S_n\), you are to compute:
\[ P = \prod_{\substack{1 \le i \le n \\ S_i \neq '0'}} S_i \quad \text{, with } P = 0 \text{ if no digit in } S \text{ is non-zero.} \]
This problem requires reading input from stdin
and sending the output to stdout
.
inputFormat
The input consists of a single line containing a string of digits. The string may be empty. Note that the input should be read from stdin
.
outputFormat
Output a single integer which is the product of all non-zero digits of the given string. If the input is empty or contains only zeros, output 0. The result should be printed to stdout
.
123405
120