#C14798. Decode Ways
Decode Ways
Decode Ways
You are given an encoded string s containing only digits. Each digit or pair of digits can be mapped to a letter using the mapping:
\(A \rightarrow 1,\ B \rightarrow 2,\ \dots,\ Z \rightarrow 26\)
Your task is to determine the total number of ways to decode the string. The decoding is valid only if it uses the above rules. Any input string that starts with '0' or contains invalid sequences should result in an output of 0
.
Example:
- Input: "12" - Output: 2
- Input: "226" - Output: 3
- Input: "0" - Output: 0
- Input: "10" - Output: 1
The problem requires you to read the input from the standard input (stdin) and output the result to the standard output (stdout).
inputFormat
A single line containing a non-empty string s of digits. The input is read from standard input (stdin).
outputFormat
An integer representing the number of ways to decode the given string, printed to standard output (stdout).## sample
12
2