Octal Fractions

http://poj.org/problem?id=1131

import java.math.BigDecimal;
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String str;
		Scanner cin = new Scanner( new BufferedInputStream( System.in ) );
		while( cin.hasNext() ){
			str = cin.nextLine();
			BigDecimal bas = new BigDecimal( 8 );
			BigDecimal ans = new BigDecimal( 0 );
			BigDecimal temp = new BigDecimal( 1 ), t;
			for( int i = 2; i < str.length(); ++i ){
				temp = temp.divide( bas );
				ans = ans.add( new BigDecimal( str.charAt( i ) - ‘0‘ ).multiply( temp ) );
			}
			System.out.println(str + " [8] = " + ans.stripTrailingZeros().toPlainString() + " [10]");
		}
		  
	}
}


Octal Fractions

上一篇:paip.提升性能----java 无锁结构(CAS, Atomic, Threadlocal, volatile, 函数式编码, 不变对象)


下一篇:photoshop合成制作出眼镜反射效果