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

Description

Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.75 in octal is 0.953125 (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.

Write a program to convert octal numerals between 0 and 1, inclusive, into equivalent decimal numerals.

Input

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]

用java的大数,感觉挺好

import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(new BufferedInputStream(System.in)); ///用BufferedInputStream据说能快点
BigDecimal ans, t, tmp;
while(sc.hasNext()){
String st = sc.nextLine(); ///字符串输入
t = BigDecimal.valueOf(1);
ans = BigDecimal.valueOf(0); int i, sta = st.indexOf('.');//找到第一次出现'.' 的位置
for(i = sta+1; i < st.length(); ++i){ ///获取字符串长度只能用length()方法
tmp = BigDecimal.valueOf(st.charAt(i) - '0'); //charAt()获取当前位置的字符
t = t.divide(new BigDecimal("8")); //大数只能和大数进行运算,Int只能与Int String只能和String
tmp = tmp.multiply(t);//乘
ans = ans.add(tmp);//加
}
System.out.println(st + " [8] = " + ans + " [10]"); ///也可用System.out.printf();
}
}
}

Poj1131-Octal Fractions的更多相关文章

  1. Octal Fractions

    Octal Fractions Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 149  Solved: 98 Description Fractions ...

  2. Octal Fractions java秒 C++

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

  3. TOJ 2861 Octal Fractions

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

  4. hdu 1376 Octal Fractions

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

  5. POJ Octal Fractions(JAVA水过)

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

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

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

  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. Redis内存管理(二)

    上一遍详细的写明了Redis为内存管理所做的初始化工作,这篇文章写具体的函数实现. 1.zmalloc_size,返回内存池大小函数,因为库不同,所以这个函数在内部有很多的宏定义,通过具体使用的库来确 ...

  2. jvm分析(MD语法)

    #是什么**jps**  查看所有的jvm进程,包括进程ID,进程启动的路径等等. **jstack**  观察jvm中当前所有线程的运行情况和线程当前状态.系统崩溃了?如果java程序崩溃生成cor ...

  3. 解决springmvc 前台取不到值

    查看web.xml 如果为web-app_2_3.xsd  spring不支持 修改项目为web-app_2_4.xsd

  4. Mysql之复制服务

    Replication[复制]使得数据可以从一个Master服务器上复制到一个或多个Slave上,默认是异步复制,不需要与Master建立永久连接:基于配置,可以作用于所有库,指定的库或库中的某些表. ...

  5. db2 Hidden columns

    When a table column is defined with the implicitly hidden attribute, that column is unavailable unle ...

  6. 按键使用方法(二)------verilog

    这里我们要验证一键两用的情况:点击与长击,单击与双击 代码: /********************************Copyright*************************** ...

  7. PHP实现执行定时任务的几种思路详解

    转:https://segmentfault.com/a/1190000002955509 PHP本身是没有定时功能的,PHP也不能多线程.PHP的定时任务功能必须通过和其他工具结合才能实现,例如Wo ...

  8. 发现一php木马代码

    <?php ;//无需验证密码! $shellname='hello~地球~猴子星球欢迎你 '; define('myaddress',__FILE__); error_reporting(E_ ...

  9. HTTP/1.1 中 If-Modified-Since 和 If-Unmodified-Since 区别简记

    接触HTTP/1.1的时日还不多, 有时候看着这两个参数老是有点混淆, 今天终于理清了, 现记录下.    初学网络, 若有理解不对, 还请拍砖. If-Modified-Since: 从字面上看, ...

  10. maven 错误: 程序包org.junit不存在

    该错误在入门例子中使用mvn clean test时出现该错误. 原因: 测试用例应该放在src/test/java/...路径下,我是放在了src/main/java/..路径下了. 因为没有遵守其 ...