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. ExceptionLess异常日志收集框架-1

    哈哈,中秋和代码更配哦,不知不觉一年过半了,祝园友们中秋快乐 前一阵子在博客园看到了一篇博文 http://www.cnblogs.com/savorboard/p/exceptionless.htm ...

  2. django redis操作

    from utils.redis.connect import redis_cache as rr.flushdb() 列表操作 r.lpush("name", xxxx) or ...

  3. VS2012使用NUGet自动下载(还原)项目中使用的包

    一: 当签出完整项目后,在解决方案名称上点右键,选择"启用NuGet程序包还原". 二: 出现询问,当然要点是,当完成后,会发现在解决方案中,多出".nuget" ...

  4. hdu 2039 三角形

    题意: 判断三条线段能否组成三角形 解法: 坑!记得用float,用int直接WA. 1: #include<stdlib.h> 2: #include<stdio.h> 3: ...

  5. BZOJ3224 普通平衡树

    传送门: Treap 版本: //OJ 1999 //by Cydiater //2016.8.30 #include <iostream> #include <cstdio> ...

  6. ionic的scroll的使用出现的问题

    今天再写ionic的时候发现了一个问题,在使用ui-view的时候引用ion-scroll指令的时候初次加载的时候能能实现拖拽滚动,只能实现滚动鼠标滚轴滚动,然后各种调试,各种比较,终于发现原来是路由 ...

  7. audio patch(10.9.3) [2.6.1]

    ; Basic Block Input Regs: rax -  Killed Regs: <nothing>0000000000048353 3D8419D411             ...

  8. phpspidercookie

    <?php /** * Created by PhpStorm. * User: brady * Date: 2016/12/9 * Time: 17:32 */ ini_set("m ...

  9. SublimeText2使用笔记

    将Sublime Text2 加入右键菜单(转) 1. 运行中输入 regedit 打开注册表 2. 在HKEY_CLASSES_ROOT/*/shell/ 下新建’项’ ,名称自己觉得.我用的是Su ...

  10. Jasper(物联网网络支撑平台公司)的技术为什么这么牛逼?

    Jasper在这个行业积累了十几年,合作的运营商超过30个,合作的行业大咖包括了通用.空客.宝马.特斯拉等几千个行业龙头,还是有很多积累下来的优势的. 一是,Jasper通过积累下来的行业应用经验,针 ...