Poj1131-Octal (fractions)

Source: Internet
Author: User
Octal Fractions
Time limit:1000 ms   Memory limit:10000 K
Total submissions:6669   Accepted:3641

Description

Fractions in octal (base 8) notation can be expressed exactly in decimal notation. for example, 0.75 in octal is 0.953125 (7/8 + 5/64) in decimal. all Octal numbers of N digits to the right of the octal point can be expressed in no more than 3N decimal digits to the right of the decimal point.

Write a program to convert octal numerals between 0 and 1, intrusive, into equivalent decimal numerals.

Input

The input to your program will consist of Octal numbers, one per line, to be converted. each input number has the form 0. d1d2d3... DK, where the di are octal digits (0 .. 7 ). there is no limit on K.

Output

Your output will consist of a sequence of lines of the form

0. d1d2d3... DK [8] = 0. d1d2d3... DM [10]
Where the left side is the input (in octal), and the right hand side the decimal (base 10) equivalent. there must be no trailing zeros, I. e. 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]

 

It feels good to use a large number of Java

Import Java. util. *; import Java. io. *; import Java. math. *; import Java. text. *; public class main {public static void main (string [] ARGs) {consumer SC = new consumer (New bufferedinputstream (system. in); // With bufferedinputstream, it is said that bigdecimal ans, T, TMP; while (SC. hasnext () {string ST = SC. nextline (); // string input T = bigdecimal. valueof (1); ans = bigdecimal. valueof (0); int I, Sta = ST. indexof ('. '); // find the first appearance '. 'location for (I = sta + 1; I <St. length (); ++ I) {// obtain the string length. Only the length () method TMP = bigdecimal can be used. valueof (St. charat (I)-'0'); // charat () obtains the character T = t at the current position. divide (New bigdecimal ("8"); // a large number can only be used with a large number, and an int can only be used with an int string and a string TMP = TMP. multiply (t); // multiply ans = ans. add (TMP); // Add} system. out. println (ST + "[8] =" + ans + "[10]"); // system is also available. out. printf ();}}}

 

Poj1131-Octal (fractions)

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.