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. iOS 8 AutoLayout与Size Class

    转自:http://www.cocoachina.com/ios/20141217/10669.html 前言 iOS8 和iPhone6发布已经过去蛮久了,广大的果粉终于迎来了大屏iPhone,再也 ...

  2. Java——Cookie与Session

    Cookie通过客户端记录信息确定用户身份,Session通过在服务器端记录信息确定用户身份. 1.Cookie  1.1概念及使用方法 Cookie实际上是一小段文本信息.客户端请求服务器,如果服务 ...

  3. 整理 iOS 9 适配中出现的坑(图文)(转)

    作者:董铂然 本文主要是说一些iOS9适配中出现的坑,如果只是要单纯的了解iOS9新特性可以看瞄神的开发者所需要知道的 iOS 9 SDK 新特性.9月17日凌晨,苹果给用户推送了iOS9正式版,随着 ...

  4. sdut 1465 公共因子

    公共因子 Time Limit: 1000MS Memory limit: 65536K 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?act ...

  5. poj 3264:Balanced Lineup(线段树,经典题)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 32820   Accepted: 15447 ...

  6. revert merge会出现的问题

    比如当我们git revert的时候, git revert Git会抱怨: is a merge but no -m option was given 这是因为你revert的那个commit是一个 ...

  7. Solr入门之(1)前言与概述

    一.前言:为何选择Solr 由于搜索引擎功能在门户社区中对提高用户体验有着重在门户社区中涉及大量需要搜索引擎的功能需求,目前在实现搜索引擎的方案上有几种方案可供选择: 1. 基于Lucene自己进行封 ...

  8. 物化视图刷新慢--有可能是mv log被多个mv使用造成的

    同事说物化视图刷新慢,经检生产环境,发现部分物化视图刷新慢的原因是:由于同一个物化视图日志(mv log)被多个物化视图(mv)使用,不同的物化视图(mv)使用不同的刷新间隔,导致物化视图日志(mv ...

  9. 11g新特性-概述 (转)

    一.新特性提纲 1.数据库管理部分 ◆数据库重演(Database Replay) 这一特性可以捕捉整个数据的负载,并且传递到一个从备份或者standby数据库中创建的测试数据库上,然后重演负责以测试 ...

  10. orientation和gravity的区别

    orientation:决定UI组件是按行还是列显示 gravity:指定文字对齐方式.