# zju1086 （高精度）解题报告

Octal Fractions

Time Limit: 1 Second      Memory Limit: 32768 KB

Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.75 in octal is 0.963125 (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, inclusive, into equivalent decimal numerals. 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. 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.75
0.0001
0.01234567

SAMPLE OUTPUT

0.75 [8] = 0.953125 [10]
0.0001 [8] = 0.000244140625 [10]
0.01234567 [8] = 0.020408093929290771484375 [10]

#include<iostream>

#include<cstring>

#include<cstdlib>

using namespace std;

int main()

{

char result[10000],a[10000];//result[]是十进制数结果，a[]是输入的8进制数

int count,len,i,j,num,temp;//len是8进制数的长度，count是十进制数的长度，num是每次取8进制数的一位转化成的整型数

while(scanf("%s",a)!=EOF)

{

count=0;//十进制数一开始的长度为0

len=strlen(a);

for(i=0;i<10000;++i)

result[i]='0';      //每次都先将结果数组置0

for(i=len-1;i>=2;--i)//从8进制数的最后一位开始取，进行高精度除法

{

num=int(a[i])-'0';//num用来存放整型数

for(j=0;j<count||num;++j)//判断条件为j超过十进制数的长度和num=0,即直到num除尽

{

if(j<count)

temp=num*10+(int(result[j])-'0');

else

temp=num*10;

result[j]=char(temp/8)+'0';//商

num=temp%8;//余数

}

result[j]='/0';//设置result数组的结尾标志符，以便输出和求长度；

count=strlen(result);//count为result数组的长度即十进制数的当前长度

}

cout<<a<<" [8] = 0."<<result<<" [10]"<<endl;

}

return 0;

}

#### 大数运算-除法-Octal Fractions

2014-04-16 21:11:13

#### ACM:&nbsp;任意进制的小数转化&nbsp;高精度题…

2016-05-19 23:22:13

#### 2765 ：八进制小数

2014-01-15 13:29:05

#### poj 百练 2765 八进制小数（精度问题）

2014-08-11 18:27:32

#### poj 1131 （小数）十进制转八进制

2016-09-19 19:57:37

#### POJ 1131 Octal Fractions (Java大数,八进制转十进制)

2016-05-14 13:17:45

#### ZSC 1218 八进制小数

2016-04-08 12:05:27

#### poj 1131 （小数）十进制转八进制

2016-09-19 19:57:37

#### zoj1086

2016-04-21 23:50:41

#### 整数大数模拟 高精度加法 高精度减法 高精度乘法 高精度除法 c/c++ java

2016-05-04 15:09:48