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. JavaScript对象与数组

    一.Object 类型到目前为止,我们使用的引用类型最多的可能就是 Object 类型了.虽然 Object 的实例不具备多少功能,但对于在应用程序中的存储和传输数据而言,它确实是非常理想的选择.创建 ...

  2. SQLServer触发器

    触发器的作用: 自动化操作,减少了手动操作以及出错的几率. 触发器是一种特殊类型的存储过程,它不同于前面介绍过的一般的存储过程. [在SQL内部把触发器看做是存储过程但是不能传递参数] 一般的存储过程 ...

  3. java.util.ConcurrentModificationException

    遍历 List 的时候将 item remove 掉会抛出此异常

  4. Swift - 代码创建单例

    创建单例的方法 import UIKit //创建一个单例类 class SingleInstance: NSObject { //在单例类中,有一个用来共享数据的数组 var datas = [St ...

  5. iOS开发人员不容错过的10大工具

    内容简介 1.iOS简介 2.iOS开发十大实用工具之开发环境 3.iOS开发十大实用工具之图标设计 4.iOS开发十大实用工具之原型设计 5.iOS开发十大实用工具之演示工具 6.iOS开发十大实用 ...

  6. Mac平台下Opencv开发环境搭建

    OpenCV(Open Source Computer Vision Library),是一个开源的跨平台的计算机视觉库,它实现了图像处理和计算机视觉领域的很多通用算法,可以在多种计算机平台上运行,支 ...

  7. Cannot return from outside a function or method

    最近发现myeclipse10中有几处bug 比如: Cannot return from outside a function or method onClick="return chec ...

  8. Tomcat在Linux上的安装与配置

    以下使用的Linux版本为: Redhat Enterprise Linux 6.5 x86_64,Tomcat版本为tomcat-7.0.54. 1.下载JDK与Tomcat.    jdk下载地址 ...

  9. mysqli的增强功能

    批量执行sql语句 批量执行dml语句 基本语法 $sqls="sql1.sql2.sql3...." mysqli::multi_query($sqls) 案例: $mysqli ...

  10. linux中解决SSH连接慢问题 关键点GSSAPIAuthentication

    [root@ok 6FE5-D831]# ssh -v xxx.xxx.xxx.64 OpenSSH_5.3p1, OpenSSL Feb debug1: Reading configuration ...