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. 基本概率分布Basic Concept of Probability Distributions 4: Negative Binomial Distribution

    PDF version PMF Suppose there is a sequence of independent Bernoulli trials, each trial having two p ...

  2. Install R & RStudio for Ubuntu

    Install R r-project.org official source to install the latest R system. add R source   sudo vi /etc/ ...

  3. [转]图片中的字符分割提取(基于opencv)

    http://blog.csdn.net/anqing715/article/details/16883863 源图片 像这些图片的字符就比较好操作,每个字符都独立,不连在一起,所以轮廓检测最好了.所 ...

  4. 深入JVM-垃圾收集器常用的GC参数

    1.与串行回收器相关的参数 -XX:+UseSerialGC:在新生代和老年代使用串行收集器 -XX:SurvivorRatio:设置eden区大小和survivor区大小的比例 -XX:Preten ...

  5. Yocto开发笔记之《工具使用:TFTP & NFS & SSH》(QQ交流群:519230208)

    QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 ======================================================== TFTP工 ...

  6. context.Request.Files为NULL问题 在实现图片上传功能的时候出现在ashx等处理页面出现context.Request.Files为NULL异常,有几点需要注意:

    .在客户端可以将form用submit提交,如下: <%@ Page Language="C#" AutoEventWireup="true" CodeF ...

  7. mysql查询区分大小写

    Mysql默认查询是不分大小写的,可以在SQL语句中加入 binary来区分大小写: BINARY不是函数,是类型转换运算符,它用来强制它后面的字符串为一个二进制字符串,可以理解为在字符串比较的时候区 ...

  8. pyqt2_官网教程

    https://pythonspot.com/en/pyqt4/ Articles You can find a collection of PyQT articles below. Applicat ...

  9. 10月21日下午PHP常用函数

    函数四要素:返回类型  函数名  参数列表  函数体 //最简单的函数定义方式 function Show() { echo "hello"; } Show();//输出结果为he ...

  10. 9月8日HTML表单元素(form、文本、按钮、选择)

    表单元素 一.form form代表表单,功能:用于申明表单,定义采集数据的范围,也就是<form>和</form>里面包含的数据将被提交到服务器或者电子邮件里.<for ...