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. scala break & continue

    Scala没有提供break和continue,我们可以自己实现一个,参考例子: import util.control.Breaks._ object BreakDemo { def main(ar ...

  2. 分布式服务框架Zookeeper

    协议介绍 zookeeper协议分为两种模式 崩溃恢复模式和消息广播模式 崩溃恢复协议是在集群中所选举的leader 宕机或者关闭 等现象出现 follower重新进行选举出新的leader 同时集群 ...

  3. ARPSpoofing教程(二) - 获取网络设备中的详细地址信息

    WinPcap中文API  http://www.ferrisxu.com/WinPcap/html/index.html 1: #include"pcap.h" 2: #incl ...

  4. 公共事件处理函数js库

    var EventUtil = { /* *添加事件处理 参数:元素对象 事件类型 处理函数 */ addHandle: function (element, type, handle) { //do ...

  5. java学习总结

    1 获得项目绝对路径 String path = request.getContextPath(); String basePath = request.getScheme() + ":// ...

  6. php 读取excel表格中的内容

    <?php /** * excel表格内容在网页中显示 * * 首先需要下载PHPExcel 工具包 * 网址: http://phpexcel.codeplex.com/releases/vi ...

  7. JS-制作可伸缩的水平菜单栏

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...

  8. 匿名函数:Lambda表达式和匿名方法

    匿名函数一个"内联"语句或表达式,可在需要委托类型的任何地方使用.可以使用匿名函数来初始化命名委托,或传递命名委托(而不是命名委托类型)作为方法参数. 共有两种匿名函数: Lamb ...

  9. 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【八】——Web Api的安全性

    系列导航地址http://www.cnblogs.com/fzrain/p/3490137.html 前言 这一篇文章我们主要来探讨一下Web Api的安全性,到目前为止所有的请求都是走的Http协议 ...

  10. 使用docker安装lamp

    docker search -s 10 lamp #搜索被收藏或使用较多的LAMP镜像,小伙伴们都推荐使用tutum/lamp docker pull tutum/lamp #下载镜像 #使用默认方式 ...