Poj 2765 decimal places (Accuracy Problem)

Source: Internet
Author: User
2765: octal decimal
  • View
  • Submit
  • Statistics
  • Prompt
  • 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 ){
...
}

This question should be a basic question. When I first saw this question, I thought it was a high-precision question. I didn't dare to use double in the beginning, later, I saw that the 8-digit number range was only 15. So I thought that double should also be able to do it. I took a look at other people's ideas. It's so clever that I can directly process it in reverse order of strings, it is worth learning to convert an octal decimal number into a decimal integer ~

The following is the code. The key to being brief is to master this kind of thinking, which is a clever way of writing;

It is different from the common method in the past;

0.75 (8) = 5/64 + 7/8;

# Include <cstdio> # include <cstring> int main () {char s [20]; int Len; Double N; while (scanf ("% s", S )! = EOF) {n = 0; Len = strlen (s); For (INT I = len-1; s [I]! = '. '; I --) // processing before the decimal point {n/= double (8.0 ); // convert to N + = double (s [I]-'0');} n/= double (8.0 ); // The one before the decimal point has not processed printf ("% s", S); printf ("[8] = %. 45g [10] \ n ", n); // % G refers to the floating point number, remove meaningless zero} return 0 ;}


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.