zoukankan      html  css  js  c++  java
  • poj 1131 Octal Fractions(高精度小数进制转换) Java

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

    import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner cin = new Scanner(System.in);
    		String str, ors;
    		BigDecimal x, y, z;
    		while (cin.hasNext()) {
    			ors = cin.next();
    			str = ors.substring(ors.indexOf(".")+1, ors.length());
    			z = new BigDecimal(0);
    			y = new BigDecimal(1);
    			for (int i = 0; i < str.length(); i++) {
    				x = new BigDecimal(str.charAt(i) - '0');
    				y = y.multiply(new BigDecimal(8));
    				x = x.divide(y, str.length()*3, RoundingMode.HALF_UP);
    				z = z.add(x);
    			}
    			System.out.println(ors + " [8] = " + z + " [10]");
    		}
    		cin.close();
    	}
    }
    


  • 相关阅读:
    [ZJOI2011]营救皮卡丘
    TJOI2018Party
    HEOI2013SAO
    [BJOI2017]树的难题
    [HNOI2016]序列
    [SHOI2007]善意的投票
    CF802C Heidi and Library (hard)
    SPOJ DIVCNT2
    LOJ子序列
    BZOJ2882工艺
  • 原文地址:https://www.cnblogs.com/xindoo/p/3595040.html
Copyright © 2011-2022 走看看