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. 软件工程个人作业-Week2

    第一部分  调研, 评测 必应词典客户端版本:安卓版5.2.2 bug描述一:在学习页面点击“单词挑战”或“我爱说英语”会弹出“加载失败,请稍后重试”,无论点击多少次都加载不出来. bug描述二:在未 ...

  2. Linux学习一周初体验

    Linux一周初体验一.准备工欲善其事,必先利其器--虚拟机+Redhat7.0构成学习的环境.安装有条不紊.按部就班.......(涉及到的KVM.VNC.Root密码重置等内容,之后再详细了解)注 ...

  3. sql自带函数语句

    --取数值表达式的绝对值select abs(-41)      41select abs(41)       41select abs(-41.12)   41.12select abs(41.12 ...

  4. HTTPS 客户端验证 服务端证书流程

    网上的文章很多, 但是对摘要的验证流程不够通俗易懂. QQ截图20160420114804.png 证书预置和申请 1:客户端浏览器会预置根证书, 里面包含CA公钥2:服务器去CA申请一个证书3: C ...

  5. Java 性能优化技巧集锦

    摘要: =================================== 可供程序利用的资源(内存.CPU时间.网络带宽等)是有限的,优化的目的就是让程序用尽可能少的资源完成预定的任务.优化通常 ...

  6. Python2.7安装(win7)

    Python可在官方网站直接下,或者百度一下Python2.7下载,这里推荐使用2.7而不是3.3,比较适合初学者 工具/原料 win7系统 python2.7安装包 方法/步骤 1.从官网下载最新的 ...

  7. extjs 兼容性问题解决方案

    首先明确一点,extjs是没有所谓的兼容性的问题的.那为什么总是出现不同浏览器兼容性的问题呢?而且很多人把这作为了extjs一个缺点. 解决方法,看看写的代码是不是多了  英文逗号 , 或 中文的逗号 ...

  8. centos linux安装telnet 过程及问题(源于内部tomcat网站,外部无法访问)

    首先本地没有telnet客户端及服务器 root权限下安装 yum install telnet yum install telnet-server vi /etc/xinetd.d/telnet 这 ...

  9. 20145212 《Java程序设计》第5周学习总结

    20145212 <Java程序设计>第5周学习总结 教材学习内容总结 第八章 1.Java中所有错误都会被打包为对象,通过try和catch语法可以对代表错误的对象做处理. try{ . ...

  10. System类

    System类是一些与系统相关属性和方法的集合,而且System类中所有的属性都是静态的,要想引用这些属性和方法,直接使用System类调用即可. //======================== ...