03: octal decimal, 03 decimal
03: octal decimal
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
All decimal places can be exactly represented. 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 between (0, 1) into decimal places.
-
Input
-
A row containing an octal decimal number. Each decimal point is in the form of 0. d1d2d3... dk. Here di is the eight decimal number 0... 7, dk is not equal to 0, and 0 <k <15 is known.
-
Output
-
Enter a row in the following format
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. Note the space position.
-
Sample Input
-
0.75
-
Sample output
-
0.75 [8] = 0.953125 [10]
-
Source
-
Translated from Southern African 2001
-
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 double ans; 7 char a[1001]; 8 int main() 9 {10 double zhishu=1;11 double fenmu;12 gets(a);13 int l=strlen(a);14 for(int i=2;i<l;i++)15 {16 fenmu=pow(8,zhishu);17 zhishu++;18 ans=ans+(double)(a[i]-48)/fenmu;19 }20 //cout<<a<<" [8] = "<<ans<<" [10]";21 printf("%s [8] = %.45g [10]",a,ans);22 return 0;23 }