Octal Fractions

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 149  Solved: 98

Description

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.

Input

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.

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.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] 因为大数除法是顺的方便,加法是逆的方便,让我纠结了好久=_=,最后觉定都顺吧,就AC了
 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
void divi(int p[],int x,int *len)
{
int temp=,i,j;
for(i=;i<*len+;i++)
{
temp=temp*+p[i];
p[i]=temp/x;
temp%=x;
} for(i=*len+;i>=;i--)
{
if(p[i])
{
*len=i+;
break;
}
} /* for(i=0;i<*len;i++)
printf("p[%d]=%d\n",i,p[i]);
printf("\n"); */
} void add(int p1[],int p2[],int *len1,int *len2)
{
int lst,i,j;
int co_p1[]; memset(co_p1,,sizeof(co_p1));
lst=*len1>=*len2?*len1:*len2; for(i=,j=lst-;i<lst;i++,j--)
{
co_p1[i]+=p2[j]+p1[j];
if(co_p1[i]>)
{
co_p1[i]-=;
co_p1[i+]++;
}
}
*len2=lst;
if(p1[i])
*len2++; for(i=,j=*len2-;i<*len2;i++,j--)
p1[i]=co_p1[j];
/* printf("和:");
for(i=0;i<*len2;i++)
printf("%d",p1[i]);
printf("\n\n");*/
} int main()
{
//freopen("a.txt","r",stdin);
int i,j,k;
int len; //放应保留的位数
int len1,len2; //len1为每个商的长度,len2
int num_a[];//放商
int num_sum[];//放商的和
char str[]; while(gets(str)!=NULL)
{
printf("%s [8] = 0.",str);
len=strlen(str);
len=(len-)*;
len2=len1=; memset(num_sum,,sizeof(num_sum)); for(i=;str[i]!='\0';i++)
{
len1=;
memset(num_a,,sizeof(num_a));
num_a[]=str[i]-'';
if(!num_a[])
{
continue;
}
else
{
for(j=;j<i-;j++)
{
divi(num_a,,&len1);
/* printf("商:");
for(k=0;k<len1;k++)
printf("%d",num_a);
printf("\n"); */
}
// printf("\n");
} add(num_sum,num_a,&len1,&len2);
} for(i=;i<=len;i++)
printf("%d",num_sum[i]); printf(" [10]\n");
}
return ;
}

Octal Fractions的更多相关文章

  1. Octal Fractions java秒 C++

    Octal Fractions 题目抽象:   将八进制小数转换成十进制小树.小数的为数很大. 可以用java  中的BigDeciaml 秒掉.  time:297ms 1 import java. ...

  2. TOJ 2861 Octal Fractions

    描述 Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0 ...

  3. hdu 1376 Octal Fractions

    刚开始做这题时,用的是0.75[8]=(7/8+5/64)[10]这个,但是总是WA…………无语了…… 后来看别人的解题报告,知道了另外一个就是0.75[8]=((5/8+7)/8)[10],从低位向 ...

  4. POJ Octal Fractions(JAVA水过)

    题目链接:id=1131" target="_blank">CLICK HERE~ 尽管java一下模拟水过,可是我看到别人的一段奇妙代码,贴出和大家共享. imp ...

  5. poj 1131 Octal Fractions(高精度小数进制转换) Java

    虽然题目那么长其实就是把8进制的浮点数转换成10进制,为了练习Java Biginteger 类 我这里用的是Java,也可以用数组模拟. import java.math.BigDecimal; i ...

  6. Poj1131-Octal Fractions

    Octal Fractions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6669   Accepted: 3641 D ...

  7. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  8. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  9. [Hanani]JAVA大数相关学习记录

    1.Basic remains 题目链接 涉及内容: |大数读入|大数模|大数进制读入时转化为十进制|大数输出时转化为其他进制输出| import java.io.*; import java.mat ...

随机推荐

  1. 2016.8.14安装myplayer心得

    安装mplayer时,我有两个os是not found状态,我在其他地方找到后 which mplayer,找到mplayer的配置界面,找到not found的部分,并且从usr/lib中找到相应的 ...

  2. Parallel Computing–Cannon算法 (MPI 实现)

    原理不解释,直接上代码 代码中被注释的源程序可用于打印中间结果,检查运算是否正确. #include "mpi.h" #include <math.h> #includ ...

  3. Web Worker

    写在前面 众所周知,JavaScript是单线程的,JS和UI更新共享同一个进程的部分原因是它们之间互访频繁,但由于共享同一个进程也就会造成js代码在运行的时候用户点击界面元素而没有任何响应这样的情况 ...

  4. IPsec 学习笔记

    工作中需要,参考网上的资料对IPSecVPN进行学习,并通过博客记录下一些知识点作为学习记录和后续复习的材料. Transport Layer (TLS) 其中主要参考了以下文档: http://ww ...

  5. 修改/etc/profile导致常用命令不可用的解决办法

    原因:/etc/profile文件修改有误 解决办法: 用/usr/bin/vim /etc/profile进入,进去后修改正确/etc/profile,然后重启机器让该文件生效即可.

  6. chrome使用技巧

    chrome使用技巧 chrome对于开发人员来说,绝对是一个神器.下面,介绍关于它的一些小技巧: 1.利用chrome快速定位source中的资源. 我之前一般如果查找每个文件,都是打开控制台,在s ...

  7. 强大的css3

    强大的css3 我们知道,这几年来智能手机的高速发展使得人们使用移动端上网的时间和人数已经超过了PC端.例如在2015年,就中国电商而言,各电商平台在移动端持续发力,移动端购物占比不断攀升,双11期间 ...

  8. HtmlAgilityPack使用

    http://stackoverflow.com/questions/5876825/htmlagilitypack-and-timeouts-on-load http://stackoverflow ...

  9. sql 查询每月的销售金额

    sql 数据分月统计,表中只有每天的数据,现在要求求一年中每个月的统计数据(一条sql) SELECT   MONTH (  那个日期的字段  ),   SUM(  需要统计的字段, 比如销售额什么的 ...

  10. C#------如何获取本机IP地址

    转载: http://www.narkii.com/club/thread-396944-1.html 代码: private string GetIpAddress() { string hostN ...