Link: http://poj.grids.cn/practice/2765/
Question:
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Decimal decimal places can be exactly expressed. For example, 0.75 in octal equals 0.963125 in decimal format (7/8 + 5/64 ). All octal decimal places with n digits after the decimal point can be expressed as decimal places with no more than 3n digits after the decimal point.
Your task is to write a program to convert the octal decimal places (0, 1) into decimal places.
-
Input
-
The input includes several octal decimal places, each occupying a row. Each decimal point is in the form of 0. d1d2d3... dk. Here di is the eight decimal number 0... 7, and 0 <k <15 is known.
-
Output
-
For each input octal decimal point, enter a row in the form below
0. d1d2d3... dk [8] = 0. D1D2D3... Dm [10]
Here, the left side is the input decimal place, and the right side is an equal decimal place. The output decimal point cannot end with 0, that is, Dm is not equal to 0.
-
Sample Input
-
0.750.00010.01234567
-
Sample output
-
0.75 [8] = 0.953125 [10]0.0001 [8] = 0.000244140625 [10]0.01234567 [8] = 0.020408093929290771484375 [10]
-
Prompt
-
If you use a string to read decimal digits, you can abort the input as follows:
Char octal [100];
While (cin> octal ){
...
}
Code:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> octal[ (cin >> sum = step = length = ( i = ; i < length; i++ sum += (octal[i] - ) * step = step * printf( }
Ideas:
1. Solve the Accuracy Problem with % 0.45g