Skew Binary
Time limit1sMemory limit128 MB
Read each skew binary string and print its decimal value, stopping at the terminating 0 line.
- Level
Easy3 of 10
- Topics
- Math, String, Implementation
- Solved
- No attempts yet
Problem
When a number is written in decimal, the -th digit (counting from the right, with the least-significant digit numbered ) represents a multiple of . For example,
When a number is written in binary, the -th digit represents a multiple of . For example,
In skew binary, the -th digit represents a multiple of . The only allowed digits are and , except that the least-significant nonzero digit may be a . For example,
The first numbers in skew binary are and . (Skew binary is useful in some applications because you can add with at most one carry. However, that has nothing to do with this problem.)
Input
The input consists of one or more lines, each containing a single integer . If , it signals the end of the input; otherwise is a nonnegative integer written in skew binary. The decimal value of is at most .
Output
For each number, output its decimal equivalent on its own line.