03: octal decimal, 03 decimal

Source: Internet
Author: User

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 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.