Octal Fractions
InterviewTime limit1sMemory limit128 MB
Read octal fractions from 0 to 1 and print each one's exact decimal value, with trailing zeros stripped.
- Level
Medium4 of 10
- Topics
- Math, String, Implementation, Simulation
- Solved
- No attempts yet
Problem
A fraction written in octal (base 8) can always be written exactly in decimal (base 10). For example, the octal number 0.75 equals in decimal. Every octal fraction with digits after the point can be written with at most digits after the decimal point.
Write a program that converts octal fractions strictly between 0 and 1 into the equivalent decimal fractions.
Input
The input is a list of octal numbers to convert, one per line. Each number has the form , where every is an octal digit ( through ). There is no limit on the number of digits . Input continues until end of file.
Output
For each input line, print one line of the form
X [8] = 0.Y [10]
where is the input octal number copied verbatim and is its decimal value. On the decimal side, strip every trailing zero so the last digit is never .